当我将本地html文件加载到我的iOS应用程序中时,每件事情都运行正常但在html文件中有一个动画(图像+声音)声音文件在文件夹引用“文件夹名为media的边缘”下建立的问题是动画图像工作正常但没有任何声音任何人可以建议我吗?
并且有我的代码
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];
答案 0 :(得分:0)
在调用webview完成加载委托时,你必须编写一些java脚本代码。
- (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>
答案 1 :(得分:0)
MyWebView.allowsInlineMediaPlayback = YES;
MyWebView.mediaPlaybackRequiresUserAction = NO;