æè¿ã¾ãLocal Player (Chrome Player)ãå®è£ ããªããã¦ãã¾ã.
ä¸å¿èª¬æãã¦ããã¨, Local Playerã¯, å®å ¨ã«ãã¼ã«ã«ã§åä½ããé³æ¥½ãã¬ã¤ã¤ã¼ã§ã.
ã·ã³ãã«ããæ±ã(å®è£ ãããã©ãããã ã), æä½ãããã(ããã¯å¤§äº), è¯ãæãã®ãã¬ã¤ã¤ã¼ã§ã.
åå¹´åã«, ã½ã¼ã¹ã³ã¼ããã¹ãã²ããã£ã«ãªã£ã¦, éçºãä¸æãã¦ãã¾ããã, æè¿ã¾ãæ¸ããªããå§ããã®ã§ã.
é³æ¥½ãã¬ã¤ã¤ã¼ããã©ã¦ã¶ã¼ä¸ã§å®è£ ããã®ã«ã¯, é³æ¥½ãã¡ã¤ã«ãJavaScriptã§èªã¿è¾¼ã¾ãªããã°ãªãã¾ãã.
ããã§HTML5ã§ããï¼ï¼ï¼
<audio src="url/to/musicfile.mp3" type="audio/mp3" />
ã¿ãããªæãã§, é³æ¥½ãåçã§ãã¾ã.
詳細ã¯ä»ã®ãã¼ã¸ã«è²ãã¾ã.
ãã¦, é³æ¥½ãã¡ã¤ã«ãåçããã«ã¯, ãã¼ã«ã«ãã¡ã¤ã«ããurlãaudioè¦ç´ ã®srcã«ãã¡ã¤ã«ãã¶ã¡è¾¼ã¾ãªããã°ãªããªãããã§ãã, ã©ãããã°ããã§ããã.
ã¾ãç´ ç´ãªå®è£ ã¯, File APIã®FileReaderã§readAsDataURLã使ããã¨ã§ããã.
å®é, Local Playerã¯ä»ã¾ã§ãã®æ¹æ³ãã¨ã£ã¦ãã¾ãã.
ã ããããããªæãã®å®è£ ã§ã
// file ã¯<input>ããå ¥ã£ã¦ããã㤠var reader = new FileReader(); reader.onerror = function(e) { console.dir(e); }; reader.onload = function(e) { var audio = new Audio(e.target.result); audio.volume = 0.5; audio.addEventListener('ended', function() { delete audio; next_music(); }); audio.play(); }; reader.readAsDataURL(file);
極ãã¦æ®éã§ãã.
æç§æ¸ãã®ã¾ãã¾ã£ã¦æãã§ã.
deleteã¯ãããªãã¨æãã¾ãã, e.target.resultã馬鹿ã§ããæååã¨ãªã£ã¦ãã, ã¡ã¢ãªã¼ããã°ããã¨ã«ãªãã¾ã.
ãã®å®è£ ãç¨ããLocal Playerã§, é³æ¥½ãåçãã¦, 10ç§åçããããã次ã®ãã¡ã¤ã«ã¸ã¨ã¹ããããã, ã¨ããåä½ãç¹°ãè¿ããæ, CPU使ç¨çã¨ã¡ã¢ãªã¼ä½¿ç¨çã¯æ¬¡ã®ããã«ãªãã¾ã.
確èªç°å¢ã¯Ubuntu, ã¡ã¢ãªã¼ã¯2GBã§ã.
æ²ãéå§ããç¬é, 5MBã®é³æ¥½ãã¡ã¤ã«ãreadAsDataURLãã¦, ã¡ã¢ãªã¼ãä¸æçã«ä¸ããã¾ã.
大ä½, å±±ã®å¤§ãããã¡ã¢ãªã¼ã®5%ããã, ã¤ã¾ã, ããã100MBã®æååãJavaScriptã®ä¸ã§ã§ãã¦ã¯æ¶ã... ãç¹°ãè¿ãã¦ãã®ã§ã.
ãããªãã ã¨, 1ç§ãã¨ã«ã¹ããããã¦è¡ã£ããã©ãã©ãã¡ã¢ãªã¼ã¯é£ãã¯CPUã¯ããã©ãã...
ããã, ï½¢æ²ãã¹ãããããï½£ã¨ããã®ã¯é³æ¥½ãã¬ã¤ã¤ã¼ã¨ãã¦ã¯, ãããããã¨ãªã®ã§ã.
ã§, ä¸å¹´éã»ã©æ©ãã§ãã¾ãã.
ä»æ¥, ç¥æ§ã®ãåãã
ξ*â ï½°â)<( ããcreateObjectURLã§ããã«ã¨ )
ã...???
ã©ãéãã®???
åãæ¢ããå®è£ ãã¦ã¿ãã...
var createObjectURL = window.URL && window.URL.createObjectURL ? function(file) { return window.URL.createObjectURL(file); } : window.webkitURL && window.webkitURL.createObjectURL ? function(file) { return window.webkitURL.createObjectURL(file); } : undefined; if (!createObjectURL) return; var audio = new Audio(createObjectURL(file)); audio.volume = 0.5; audio.addEventListener('ended', function() { delete audio; next_music(); }); audio.play();
ã ããããããªæãã®å®è£
ã¯ã, ã¨ã£ã¦ãã¨ã¼ã£ã¦ãç°¡åã§ãã (ã«ãã«ã
åãæ¢ãããã£ãã¨åãæ¡ä»¶ã§, é³æ¥½ãèªã¿è¾¼ãã§æ¬¡ã ã¨ã¹ããããã¦ã¿ã¾ã
.......
ãããããããã...
ã¡ã¢ãªã¼...ä¸å®ããã...
ãã, ããã°è¦ã¦ã人ã«ã¯åãããªãã§ãããã, ã¡ããã¨é³æ¥½ãèããã¦ã¾ãã, ã¹ããããã¦ã¾ãã...
åãããããããã«, é³æ¥½ãåçããç¬éã«CPUã«ã¯ã¶ã¨è² è·ãä¸ãããããªæãã®ã³ã¼ããå ¥ãã¦ã¿ã¾ã.
for (var i = 0; i < 2e4; i++) { console.log(i); };
ããã§, ãã£ãã¨åãæ¡ä»¶ã§è¡ã£ã¦ã¿ã¾ã.
ã¡ããã¨é³æ¥½æµãã¦ããã§ããï¼ ãã³ãã«. ãã³ãã§ã.
ã¡ã¢ãªã¼å
¨ç¶é£ã£ã¦ãªãããã...ï¼¼ã¤ãã§ï¼
ã¾ã¨ã
createObjectURLã¯åã*1
ä½ãåãã£ã¦, å ¨ç¶ãµã£ã¤ã¼ã®é¢æ°å¼ã³åºãã§æ¸ãã¦ãã®ã«, è£ã§ã¯urlå ã®ãã¼ã«ã«ãã¡ã¤ã«ãstream(?)çã«èªã¿è¾¼ãã§ã.
ã, ãã, èªã¿è¾¼ãã§ãã®ã¯audio elementã®æ¹ãªã®ããª...
ããã¾ã§ã¯, readAsDataURLã§ä¸æ°ã«èªã¿è¾¼ãã§ãããã, 50MBãã1æéè¶ ã®ãã¡ã¤ã«ãåçã§ãã¾ããã§ãã.
ãããcreateObjectURLã«ãã£ã¦è§£æ±ºããã¦ãã¾ã£ãã®ã§ã.
ããã«, ããã¾ã§ã§ããªãã£ãåç»åçãå¯è½ã«ãªãã¾ã!!! â ãªãã¾ãã!!!
createObjectURL, ã©ãããå®è£ ã«ãªã£ã¦ããã§ããã?
ã¡ããã¨é³æ¥½ãåç»ã®ã·ã¼ã¯ãã§ããã, ãããä¸æè°ã§ã.
ä¸æè°ãªã®ã¯, USBæ¥ç¶ã®å¤ä»ãHDDãªã©ã«ããé³æ¥½ã, åçãã¦ç´ãã«USBãã¶ã£ãã¬ãã¦ã, ãã®ã¾ã¾é³æ¥½ãèããç¶ãããã¨ãªãã§ã.
ãã, ã¾ãV8ã®éã«åãè¾¼ã¾ãããã«ãªã£ã¦ãã¾ã£ãã...
追è¨(2012/11/21)
Local Playerã¯manifest_version: 2ã®æ³¢ã«ã¤ãã¦ãããªãã¦Storeããåé¤ããã¾ãã.
*1:ã©ãããã, åãã£ã¦æã£ã次ã®æ¥ã«ã¯, ãã®URLãä¸æçãªãã®ã ã¨ãããã¨ã«æ°ãã¤ãã¦èãã. ã¿ããªã³ã³ã§å°ã£ã¦ã. ä¾ãã°How to save the window.URL.createObjectURL() result for future use? createObjectURLã«é¢ããã»ãã¥ãªãã£ã¨ãåå¼·ããã