iOS/Android 㧠HTML5 ã® audio/video ãä»»æã®ã¿ã¤ãã³ã°ã§åçããæ¹æ³
HTML5 ã§è¿½å ããã audio/video å±æ§ã«ãã£ã¦ããã©ã°ã¤ã³ã¬ã¹ã§åç»ãé³å£°ã®åçãå¯è½ã«ãªã£ããã¨ã¯ããç¥ããã¦ãã¾ãããã¢ãã¤ã«ï¼ã¹ããï¼ã§ããã®åçã¿ã¤ãã³ã°ã®å¶ç´ãå³ãããã¨ã¯æ¡å¤ç¥ããã¦ãã¾ãããããã¯ä»¥åãå½Blogã§ã HTML5 x Touch UI の UXを考える(補足) ã® User action event restrictions ã§ããã©ãã¨æ¸ãã¾ãããã¾ããã¦ããã®å¶ç´ã«è¦ãããããªããããªãã¨ã解決çãè¦ãã ããã®ã§ãGWæä¸ã«ãé¢ãããä¹ ãã¶ãã®ã¨ã³ããªã¼ã§ãã
ã¾ããæ¬å®¶ Apple ã®ããã¥ã¡ã³ãã«ã以ä¸ã®ããã«ããã¾ãã
iOS-Specific Considerations
In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. No data is loaded until the user initiates it. This means the JavaScript play() and load() methods are also inactive until the user initiates playback, unless the play() or load() method is triggered by user action. In other words, a user-initiated Play button works, but an onLoad="play()" event does not.
ï¼è¶ æ訳ï¼
iOS ã® Safari ã§ã¯ãã¦ã¼ã¶ã¼ãæºå¸¯ç¶²ã§éé課éããããããããªããããpreload 㨠autoplay ã¯å¹ããªãããã¦ã¼ã¶ã¼ãä½ãã¢ã¯ã·ã§ã³ããªãã¨ãJavaScript ã§ã® play() ã load() ããã¡ãã¤ã¾ããåçãã¿ã³ãæ¼ã㦠play() ãå¼ã¹ããã©ãonload 㧠play() ãã¦ãç¡å¹ã ããã
ãã®ã¦ã¼ã¶ã¼ã¢ã¯ã·ã§ã³ã¨ããã®ãçµæ§å³ãããtouch/mouseã¤ãã³ãã®ç´æ¥ã®ãã³ãã©å ã§ããå¹ãã¾ãããsetTimeoutãªã©ã®ã¿ã¤ãã¼ãæãã¨ããã¢ã¦ãã§ãã
ä¾ãã°ã以ä¸ã®ãããªã³ã¼ãã¯åçã§ãã¾ããhttp://jsfiddle.net/dsuket/jTh3v/
var playBtn = document.getElementById('play'); playBtn.addEventListener('click', function() { audio.play(); }, false);
ããããããã«ã¿ã¤ãã¼æãã¨åçããã¾ããã http://jsfiddle.net/dsuket/Ny9Xz/ ï¼PCãã©ã¦ã¶ã§ã¯åçã§ãã¾ãï¼
var playBtn = document.getElementById('play'); playBtn.addEventListener('click', function() { setTimeout(function(){ audio.play(); }, 2000); }, false);
ãã㯠setTimeout ã ããããªããä¾ãã° transitionEnd ãªã©ã®ã¢ãã¡ã¼ã·ã§ã³é¢é£ã®ã¤ãã³ããªã©ããã¡ã§ããããããã¨ãã¢ãã¡ã¼ã·ã§ã³çµäºæã®ã¿ã¤ãã³ã°ã§é³å£°ãåçãããå ´åã«é常ã«å°ãã
ããã§ã以ä¸ã®ããã«ããã¨åçã§ãã¾ããhttp://jsfiddle.net/dsuket/rWpM7/
var playBtn = document.getElementById('play'); playBtn.addEventListener('click', function() { audio.load(); setTimeout(function(){ audio.play(); }, 2000); }, false);
ãã¤ã³ãã¯ãsetTimeout ã®åã« load() ãããã¨ã§ããplay() ã¡ã½ããã¯å é¨ã§èªåçã« load ãå¼ã°ããã®ã§ãããã¿ã¤ãã¼ãã³ãã©ã®ä¸ã§ã¯ãã® load ãææ¢ããã¦ããããã§ããããã§ãã¦ã¼ã¶ã¼ã¤ãã³ããçºçãã段éã§ããã« load() ã ãå¼ã³åºããå¾ã¯ä»»æã®ã¿ã¤ãã³ã°ã§ play() ããã°OKï¼
ãªããããã¥ã¡ã³ãonload ã®ã¿ã¤ãã³ã°ã§èªååçããããã¨ããã®ã¯ãã¯ãã§ãã¾ãããããã§ãå°ãç»é¢ããã¼ã工夫ãã¦ãæåã«ã¹ãã©ãã·ã¥ç»é¢ãç¨æããã¿ãããã¦ãããããã«ãã¾ãããã®ã¿ããã¤ãã³ããã³ãã©ã®ä¸ã§ããªã¼ãã£ãªãã¡ã¤ã«ããã¼ããã¾ããHTML5 Webã¢ããªã§ãã使ããã Single Page Applicationã®å ´åãããã§å¿ è¦ãªãªã¼ãã£ãªãã¡ã¤ã«ãå ¨é¨ãã¼ããã¦ãã¾ãã¨è¯ãããã§ããããããã°å¾ã¯å¥½ããªã¿ã¤ãã³ã°ã§é³å£°ãåçã§ãã¾ãã
audioã«ã¤ãã¦ã®èª¬æã§ããããvideoãåæ§ã®åé¡ãããã¾ããæ¤è¨¼ã§ãã¦ã¾ããããåãããã«ããã°å¯¾å¿ã§ãããã§ãã
ãã ãaudio/videoã®èªååçãåçã¿ã¤ãã³ã°ã¯OSãã¼ã¸ã§ã³ã§ã³ãã³ããããã¾ãããããã iOS4.1ãAndroid 2.3 ã¾ã§ã¯ setTimeout ã®ä¸ã§ãåçã§ãã¾ãããããã iOS 5ãAndoroid 4 ãããããåçã§ããªããªãã¾ããããã¼ã¸ã§ã³ãéãã°ãã® load ãåãé¢ãæ¹æ³ãã¾ã使ããªããªãããããã¾ãããååæ¤è¨¼ã«ã¯æ°ãã¤ãã¦ãã ããã
åè: