HTML5¼¼Êõ

Ä£ÄâÖÆ×÷ÍøÒ×ÔÆÒôÀÖ(AudioContext) - _ºýһЦ

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-11-07 16:03 ÎÒÒªÆÀÂÛ( )

¼ÇµÃºÃÔçÇ°ÔÚĽ¿ÎÍøÉÏ¿´µ½Ò»¿î¿ÉÊÓ»¯ÒôÀÖ²¥·ÅÆ÷£¬µ±Ç°ÊǾõµÃºÜÊÇÉñÆ棬»¹ÄÜÕâôÍæ¡£ÓÉÓÚµ±Ê±¸Õ¸ÕתÐв»¾Ã£¬ºÃ¶à¶«Î÷¿´µÃÏ¡ÀïºýÍ¿²»Ã÷°×£¬ÓÚÊdzÃ×ÅÏÖÔÚÓÐʱ¼äÓÖÖØÐÂÊáÀíÁËÒ»±é£¬È»ºó²ÎÕÕ¹ÙÍøµÄAPIÄ£Äâ×öÁËÒ»¿îÍøÒײ¥·ÅÆ÷¡£Ã»ÓÐʲô´´Ðµĵ㣬ֻÊÇÏëµ½Á˾ÍÏë×ö

¼ÇµÃºÃÔçÇ°ÔÚĽ¿ÎÍøÉÏ¿´µ½Ò»¿î¿ÉÊÓ»¯ÒôÀÖ²¥·ÅÆ÷£¬µ±Ç°ÊǾõµÃºÜÊÇÉñÆ棬»¹ÄÜÕâôÍæ¡£ÓÉÓÚµ±Ê±¸Õ¸ÕתÐв»¾Ã£¬ºÃ¶à¶«Î÷¿´µÃÏ¡ÀïºýÍ¿²»Ã÷°×£¬ÓÚÊdzÃ×ÅÏÖÔÚÓÐʱ¼äÓÖÖØÐÂÊáÀíÁËÒ»±é£¬È»ºó²ÎÕÕ¹ÙÍøµÄAPIÄ£Äâ×öÁËÒ»¿îÍøÒײ¥·ÅÆ÷¡£Ã»ÓÐʲô´´Ðµĵ㣬ֻÊÇÏëµ½Á˾ÍÏë×öһ϶øÒÑ¡£

Ч¹û¿ÉÒÔ¿´ÕâÀ£¬Èç¹û¿´²»ÁË£¬ËµÃ÷²©Ö÷µÄ·þÎñÆ÷ÒѾ­²»ÔÚ¹¤×÷À²¡££¨½¨ÒéʹÓõçÄÔä¯ÀÀÆ÷´ò¿ª£¬Í¬Ê±Çл»µ½ÊÖ»úģʽÀ´´ò¿ª£¬ÒòΪÔÚÊÖ»úÉϲâÊÔʱÓÐÎÊÌ⣬¶øÇÒÓкܴóÐÔÄÜËðºÄ£¬¾­³£»áµ¼ÖÂä¯ÀÀÆ÷±¼À££©

´úÂëÔÚÕâÀgithub

Ч¹ûͼһÀÀ£º

xiaoguo

¿´×Å×Ô¼ºÑóÑóÈ÷È÷дÁË¿ì1000¶àÐеÄjs£¬ÎÒÏÖÔÚÐÄÀïÒ²ÊÇÒ»Íòƨ²ÝÄàÂíÆ®¹ý¡£µ±È»ÆäÖл¹Óкܶà´úÂëûÓо­¹ýÌáÁ¶£¬ºÜ¶à±äÁ¿¿ÉÒÔ¹«Óã¬ÓöÔÏ󻯵ķ½Ê½À´ËµÐ´Õâ¸ö»á¸üÓÐÌõÀí£¬Õâ¸ö²©Ö÷ÒÔºóÓÐʱ¼äÔÙÊáÀíÒ»±é¡£ÏÂÃæÀ´½²½²Ö÷ÒªµÄʵÏÖ¹ý³Ì¡£

Ò»¡¢ÕûÌå˼·

API¿ÉÒÔµ½ÉÏÃæÈ¥¿´£¬Ö»ÊÇÒ»¸ö²Ý°¸£¬²¢Ã»ÓÐÄÉÈë±ê×¼£¬ËùÒÔÓÐЩµØ·½»¹ÊÇÓÐÎÊÌ⣬ÔÚÏÂÃæÎÒ»á˵µ½ÎÒÓöµ½ÁËʲôÎÊÌâ¡£µ«ÊÇÕâ¸ö²Ý°¸ÉϵĶ«Î÷Æäʵ¿ÉÒÔ×ö³öºÜ¶àÆäËûµÄЧ¹û¡£±ÈÈç¶àÒôƵԴÀ´´ïµ½»ìÒôЧ¹û¡¢ÒôƵÕñµ´Æ÷Ч¹ûµÈµÈ...

ÕûÌåµÄ˼·ͼÈçÏ£º

silu

´óÖÂÉÏÀ´Ëµ¾ÍÊÇͨ¹ýwindowÉϵÄAudioContext·½·¨À´´´½¨Ò»¸öÒôƵ¶ÔÏó£¬È»ºóÁ¬½ÓÉÏÊý¾Ý£¬·ÖÎöÆ÷ºÍÒôÁ¿¿ØÖÆ¡£×îºóͨ¹ýBufferSourceNodeµÄstart·½·¨À´Æô¶¯ÒôƵ¡£

¶þ¡¢¾ßÌå·ÖÎö 2.1 ·ÓÉ

routes/index.js

(req(err() { first = names[1]; names song )...nameslistPostssongsingerlistPosts[0] ); });

ÕâÀïmacƽ̨ºÍwindows²»Í¬£¬macÎļþ¼Ð»áÓÐÒ»¸ö.DS_StoreÎļþ£¬Òò´Ë×÷ÁËÒ»µãС´¦Àí¡£

ÁíÍâÓÉÓÚÓõĺ£Íâ·þÎñÆ÷£¬ËùÒÔÇëÇómp3×ÊÔ´µÄʱºò»áÓкܳ¤Ê±¼ä£¬Òò´ËÎÒ°ÑÒôƵ×ÊÔ´·ÅÔÚÁËÆßÅ£ÔÆ£¬¶ø²»ÊÇ´Ó±¾µØ»ñÈ¡£¬µ«ÊÇÊý¾Ý»¹ÊÇÔÚ±¾µØÄã¬ÒòΪ²¢Ã»ÓÐÓõ½Êý¾Ý¿â¡£

2.2 Ö÷Ò³Ãæ

Ò³ÃæÔËÓÃÁËÊÖÌÔµÄflexible£¬Òò´ËÔÚ×ʼÇл»µ½ÊÖ»úģʽµÄʱºò£¬¿ÉÄÜÐèҪˢÐÂÒ»ÏÂä¯ÀÀÆ÷²ÅÄÜÏÔʾÕý³£¡£Ñùʽ²ÉÓõÄÊÇÔ¤´¦Àísass£¬¸ÐÐËȤµÄ¿ÉÒÔÈ¥¿´Ò»Ï´úÂë

2.3 ´´½¨ÒôƵ

(buffer) () { ac .webkitAudioContext)(); } audioBuffer onStateChange; // ´´½¨BufferSrouceNode bufferSource .gainNode .analyser ....connect(ac.destination); }

½áºÏÉÏÃæµÄͼ£¬ÕâÀï´´½¨ÒôƵµÄ´úÂë¾Í±È½ÏºÃÀí½âÁË¡£

2.4 ²¥·Å

²¥·ÅÆäʵÊÇÒ»¸ö·Ç³£¼òµ¥µÄAPI£¬Ö±½Óµ÷ÓÃBufferSourceNodeµÄstart·½·¨¼´¿É£¬start·½·¨ÓÐÁ½¸öÎÒÃÇ»áÓõ½µÄ²ÎÊý£¬µÚÒ»¸öÊÇ¿ªÊ¼Ê±¼ä£¬µÚ¶þ¸öÊÇʱ¼äλÒÆ£¬¾ö¶¨ÁËÎÒÃÇ´Óʲôʱºò¿ªÊ¼£¬Õ⽫ÔÚÌø²¥µÄʱºò»áÓõ½¡£

ÁíÍâÓÐÒ»¸ö×¢ÒâµÄµãÊÇ£¬²»ÄÜÔÙͬһ¸öBufferSourceNodeÉϵ÷ÓÃÁ½´Îstart·½·¨£¬·ñÔò»á±¨´í¡£

bufferSource && bufferSource.start(0);

2.5 »ñȡƵÆ×ͼÊý¾Ý

() ((arr); renderInter

ͨ¹ý²»¶Ï´¥·¢Õâ¸öº¯Êý£¬½«×îеÄÊý¾ÝÌî³äµ½Ò»¸ö8λµÄÎÞ·ûºÅÊý×éÖУ¬½ø¶ø¿ªÊ¼äÖȾÊý¾Ý¡£´ËʱµÄÒôƵ·¶Î§Ä¬ÈÏÉèÖÃΪ256¡£

2.6 ÒôÁ¿µ÷½Ú

ÒôÁ¿µ÷½ÚÒ²ÓÐÏֳɵÄAPI£¬ÕâµãҲûʲô¿É½²µÄ¡£

.];

2.7 ÔÝÍ£Óë»Ö¸´²¥·Å

ÎÒÔÚAudioBufferSourceNodeÉÏÕÒÁ˺þ㬱¾À´ÒÔΪÓÐstart/stop·½·¨£¬ÄÇô¾Í»áÓÐÀàËÆÓÚpuase·½·¨Ö®ÀàµÄ£¬µ«ÊÇÒź¶µÄÊÇ£¬È·ÊµÃ»ÓС£×ʼÎÒÒ²²»ÖªµÀÔõô×ö²¥·ÅºÍÔÝÍ££¬µ«ÊǺÃÔÚÌìÎÞ¾øÈË֮·£¬ÒâÍâ·¢ÏÖÔÚÈ«¾ÖµÄAudioContextÉÏÓÐÁ½¸ö·½·¨resume/suspend£¬ÕâÒ²ÊÇʵÏÖ²¥·ÅºÍÔÝÍ£µÄÁ½¸ö·½·¨¡£

() { playState ().(); // ÖØÆô¶¨Ê±Æ÷ startInter && clearInterval(startInter); startInter (start(startSecond, totalTime); startSecond)() { playState ()(); startInter .suspend(); }

2.8 Ìø¶¯²¥·Å

Ìø¶¯²¥·ÅÐèÒªÓõ½¿ªÊ¼Ê±¼ä£¬ÕâÀïÎÒĬÈÏÉèÖÃΪ0£¬½ÓÏÂÀ´¾ÍÊÇʱ¼äλÒÆÁË¡£Í¨¹ýÌø¶¯²¥·Å½ø¶ÈÌõµÄÓα꣬ÎÒÃDz»ÄѼÆËã³öÎÒÃÇÓ¦¸Ã²¥·ÅµÄʱ¼ä¡£

ÕâÀïÓÐÒ»¸öÎÊÌ⣬ÎÒ֮ǰҲ˵µ½¹ý£¬¾ÍÊÇÔÚͬһ¸öAudioBufferSourceNodeÉϲ»ÄÜͬʱstartÁ½´Î£¬ÄÇôҲ¾ÍÊÇ˵£¬ÎÒÈç¹ûÕâÀïÔÙÖ±½Óµ÷ÓÃstart(0, offsetTime)½«»á±¨´í£¬Êǵģ¬ÕâÀïÎÒÒ²¿¨Á˺þã¬×îºóÔÙÒ»¸öÂÛ̳(ÊÇÄĸöÎÒµ¹ÊÇÍü¼ÇÁË)ÉϸøÁËÒ»¸ö½¨Ò飬²»ÄÜͬʱÔÚÒ»¸öAudioBufferSourceNodeÉÏstartÁ½´Î£¬ÄǾÍÔÚ²»Í¬µÄAudioBufferSourceNodeÉÏstart£¬Ò²¾ÍÒâζ×ÅÎÒ¿ÉÒÔн¨Ò»¸ö½Úµã£¬È»ºóÒÀÈ»ÓÃ֮ǰajaxÇëÇóµ½µÄÊý¾ÝÀ´´´½¨Ò»¸öеÄÒôƵÊý¾Ý¡£ÊµÑéÊÇ¿ÉÒÔÐеġ£

(time) analyser && analyser.disconnect(gainNode); gainNode && gainNode.disconnect(ac.destination); bufferSource .gainNode .analyser ...onPlayEndedtime); playState ()()(start, executeTime(time)); startSecond (); // ÖØпªÊ¼¼Æʱ startInter && clearInterval(startInter); startSecond++; startInter (start(startSecond, totalTime); startSecond); }

2.9 ÁбíÑ­»·

ÁбíÑ­»·Óõ½ÁËbufferSourceÉϵÄÒ»¸ö»Øµ÷·½·¨onended£¬ÔÚ²¥·ÅÍê³ÉÖ®ºó¾Í×Ô¶¯Ö´ÐÐÏÂÒ»Çú¡£

() .(acState skip) ()

ÕâÀïÓÐÒ»¸ö¿Ó¾ÍÊǵ±ÎÒµã»÷ÁËÉÏÒ»ÇúºÍÏÂÒ»ÇúµÄʱºò£¬·¢ÏÖÒ²»áÖ´ÐÐÕâ¸ö»Øµ÷£¬Òò´Ëµã»÷ÏÂÒ»ÇúµÄʱºò£¬Êµ¼ÊÉϲ¥·ÅµÄÊÇÏÂÁ½ÇúµÄ¸èÇú¡£Òò´ËÕâÀï×öÁËÇø·Ö£¬µ±µã»÷ÉÏÒ»ÇúºÍÏÂÒ»ÇúµÄʱºò£¬»á¸øskipÉèÖÃΪtrue£¬ÕâÑù¾Í²»»áÖ´ÐÐÕâ¸ö·½·¨ÖÐĬÈϵÄÐÐΪ¡£

Èý¡¢ÊÖ»ú¶Ë»áÓеÄÎÊÌâ

֮ǰ˵¹ý£¬½¨Òé²»ÒªÔÚÊÖ»ú¶ËÔËÐУ¬ÒòΪ»áÓÐһЩÎÊÌ⣬Ö÷Òª±íÏÖÔÚ£º

ËÄ¡¢×ܽá

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • ÕÕƬ²é¿´Æ÷µÄÖÆ×÷´úÂë - winpin

    ÕÕƬ²é¿´Æ÷µÄÖÆ×÷´úÂë - winpin

    2017-10-27 12:00

  • [js¸ßÊÖ֮·]html5 canvas¶¯»­½Ì³Ì - ±ß½çÅжÏÓëСÇòÁ£×ÓÄ£ÄâÅçȪ,É¢µ¯Ð§¹û - ghostwu

    [js¸ßÊÖ֮·]html5 canvas¶¯»­½Ì³Ì - ±ß½çÅжÏÓëСÇòÁ£×ÓÄ£ÄâÅçȪ,É¢

    2017-10-10 18:01

  • [js¸ßÊÖ֮·] html5 canvas½Ì³Ì - ÖÆ×÷Ò»¸öÊýÂëµ¹¼ÆʱЧ¹û - ghostwu

    [js¸ßÊÖ֮·] html5 canvas½Ì³Ì - ÖÆ×÷Ò»¸öÊýÂëµ¹¼ÆʱЧ¹û - ghostwu

    2017-10-09 11:03

  • ÓÃcss3ÖÆ×÷ÃÀºïÍõË¢½ð¹¿°ô - ÖðÃÎJack

    ÓÃcss3ÖÆ×÷ÃÀºïÍõË¢½ð¹¿°ô - ÖðÃÎJack

    2017-08-26 12:02

ÍøÓѵãÆÀ
Ç