簡體   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