when i load local html file into my iOS app every thing work fine but in the html file there is an animation (images+sounds) the sounds file founded under the folder reference "edge in folder named media " the problem is the animated images work fine but without any sound can any one advice me ?
and there is my code
localContent = [[UIWebView alloc] initWithFrame:CGRectMake(0, 60, 1024, 768)];
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"inDirectory:@"Edge"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[localContent loadRequest:request];
[self.view addSubview: localContent];
You have to write some java script code when your webview finish loading delegate is called..
- (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:
<script>
function startVideo(){
var pElement3 = document.getElementById('myVideo');
pElement3.play();
}
</script>
And here's the html in case you're 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>
MyWebView.allowsInlineMediaPlayback = YES;
MyWebView.mediaPlaybackRequiresUserAction = NO;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.