繁体   English   中英

将HTML文件加载到iOS应用中

[英]Loading Html File into iOS app

当我将本地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];

在调用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>

MyWebView.allowsInlineMediaPlayback = YES;

MyWebView.mediaPlaybackRequiresUserAction = NO;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM