2014/06/13

[iOS][html5]audioタグがpreloadできない件

html5から導入されたaudioタグですが、レンダリングするときに、preload属性をつけて前もってロードすることができます。

<audio src="hoge.m4a" preload></audio>
これ、iOSのブラウザからアクセスすると、preloadされないようだ。

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.

This plays the movie: <input type="button" value="Play" onclick="document.myMovie.play()">

This does nothing on iOS: <body onload="document.myMovie.play()">

via:User Control of Downloads Over Cellular Networks
従って、自動再生したい場合は、下のように組み直す必要がある。
//play and pause it once
document.addEventListener('touchstart', function () {
    document.getElementsByTagName('audio')[0].play();
    document.getElementsByTagName('audio')[0].pause();
});

//now play whenever you want it to play
確かに上で、再生された。

むちゃくちゃめんどくさいんだけどw

参考
iOS/Android で HTML5 の audio/video を任意のタイミングで再生する方法
iPhone HTML5 Audio tag not working

0 コメント:

コメントを投稿