Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

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();"];
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away