Autoplay HTML5 audio/video in iOS5

后端 未结 3 1169
慢半拍i
慢半拍i 2020-12-17 04:18

I have an HTML5 web-app that has sound effects. I\'m trying to get these effects working in iOS5 and can\'t for the life of me.

Wondering if anyone has any work-aro

3条回答
  •  误落风尘
    2020-12-17 05:18

    Due to Apple, they have restricted the auto-play features to prevent cell data charges. In xcode4 i added a workaround though. In your "webViewDidFinishLoad" Send a javascript call to auto play the video and it works. I tried this in the html file with regular javascript but it did not work. Doing it through webViewDidFinishLoad did the trick though. In this example i want to auto play the video on my index.html page. I have a javascript function on that page called startVideo().

    - (void)webViewDidFinishLoad:(UIWebView *)webView{
        NSURLRequest* request = [webView request];
        NSString *page = [request.URL lastPathComponent];
        if ([page isEqualToString:@"index.html"]){
            NSString *js = @"startVideo();";
            [myWebMain stringByEvaluatingJavaScriptFromString:js];
        }
    }
    

    And here's my javascript function:

    
    

    And here's the html in case you're new to html video

    
    

提交回复
热议问题