HTML5 audio / video playback in iOS5

I have an HTML5 web application that has sound effects. I am trying to get these effects to work in iOS5 and cannot for me.

I wonder if anyone has any actions to get the JS control of HTML5 audio / video control in iOS5.

Or even a way to manage multiple audio files with one click. Since it costs right now, if I have 10 sound effects, I will need 10 user clicks to get control of all of them, absurd !

+4
source share
3 answers

It's absurd, but you have to see it from the iPhone or from the perspective of a mobile phone. This is a mobile phone that crosses a cellular network with bandwidth limitations that many people are aware of from Sprint’s recent commercial ad. They don’t want users to go beyond the bandwidth because some site sends their phone to a lot of data without taking any action.

Below is an excerpt from the official Safari Developer Library with more details.

User control over downloads over cellular networks

In Safari on iOS (for all devices, including the iPad), where the user can be on the cellular network and charge per unit of data, preload and auto play are disabled. No data is downloaded until the user initiates it. This means that the JavaScript play () and load () methods are also inactive until the user starts to play, unless the play () or load () method is triggered by the user action. In other words, a user-initiated game button works, but the onLoad = "play ()" event does not work.

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

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

+7
source

Due to Apple, they have limited auto-play features to prevent cellular network data outages. In xcode4, I added a workaround. In your "webViewDidFinishLoad" Send a javascript call to automatically play the video and it works. I tried this in an html file with regular javascript, but that didn't work. However, do it through webViewDidFinishLoad. In this example, I want to automatically play the video in my index.html page. I have a javascript function on this 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 is my javascript function:

 <script> function startVideo(){ var pElement3 = document.getElementById('myVideo'); pElement3.play(); } </script> 

And here is the html if you are new to html video

 <video id="myVideo" poster="index_poster.png" width="1024" height="768" xcontrols autoplay="autoplay"> <source src="flow.m4v" type="video/mp4"/> browser not supports the video </video> 
+6
source

Have you tried something like this?

 function clickedOnce(){ $('audio').each(function(){ this.play(); }); } 
0
source

Source: https://habr.com/ru/post/1380098/


All Articles