WKWebView嵌入视频在发布后继续播放声音

编程入门 行业动态 更新时间:2024-10-25 15:28:03
本文介绍了WKWebView嵌入视频在发布后继续播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在实施一项使用webview播放视频文件的服务。我从UIWebView迁移到WKWebView,并试图用它播放Youtube和Coub视频。几乎所有东西都没问题,在iOS 8中没有崩溃,但是在WKWebView发布并从屏幕上移除后,视频声音会持续播放一段时间(在某些情况下大约需要45秒)。

I'm implementing a service for playing video files with a webview. I migrated from UIWebView to WKWebView, and trying to play Youtube and Coub videos with it. Almost everything is okay, no crashes in iOS 8, but after WKWebView released and removed from screen, video sound keeps playing for a while (in some cases about 45 seconds).

我找不到停止视频声音的方法。我试图用媒体播放器捕获系统通知,但没有成功。

I can't find the way to stop sound of video. I tried to catch system notifications with a media player, but no success.

有没有办法在WKWebView中停止声音或视频?

Is there any way to stop sound or video in WKWebView?

WKWebview配置是下一个:

WKWebview configuration is next:

//javascript for configurate video viewport (not full screen) NSString *jScript = [NSString stringWithFormat:@"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=%d, height=%d, initial-scale=1, maximum-scale=1'); document.getElementsByTagName('head')[0].appendChild(meta);", (int)VIEW_WIDTH, (int)VIEW_HEIGHT ]; WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]; WKUserContentController *wkUController = [[WKUserContentController alloc] init]; [wkUController addUserScript:wkUScript]; WKWebViewConfiguration *config = [WKWebViewConfiguration new]; config.mediaPlaybackAllowsAirPlay = YES; config.userContentController = wkUController; _wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT) configuration:config]; [_wkWebView setBackgroundColor:RGB(0x0a0a0a)]; [_wkWebView setNavigationDelegate:self]; [self insertSubview:_wkWebView atIndex:0];

推荐答案

您可以加载空白页 [NSURL URLWithString:@about:blank]

虽然可能有更好的解决方案

There is probably better solution though

更新:已在iOS 8.3中修复

UPDATE: fixed in iOS 8.3

更多推荐

WKWebView嵌入视频在发布后继续播放声音

本文发布于:2023-07-11 12:07:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1093998.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:声音   视频   WKWebView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!