4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UIWebViewのAudio/Videoが自動再生されない。

Last updated at Posted at 2012-06-06

UIWebViewのhtmlロード後自動にAudio/Videoを再生しようとしたが再生できない。

Javascript
$(document).ready(function() {
	var audio = new Audio('./test.mp3');
	audio.play();
});

探してみたら、Appleがトラフィックを気にして自動再生できないように決めたらしい。
結局Javascriptで関数を作って「webViewDidFinishLoad:」で呼出すようにして解決した。

Javascript
var audio;

var playAudio = function() {
	audio.play();
};

$(document).ready(function() {
	audio = new Audio('./test.mp3');
});
ObjectiveC
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    [webView stringByEvaluatingJavaScriptFromString:@"playAudio();"];
}
4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?