iphone - 通过 HTML 打开的全屏播放器即使按下完成也不会停止下载

标签 iphone ios html uiwebview

我使用 tableview 在同一单元格中添加了几个视频。每个单元格都有自己的 WebView 。使用以下代码在 webview 中播放视频

NSString *embedHTML = @"<html><head>\<style type=\"text/css\">\body {\background-color:transparent;\color: white;\}\</style>\<script>\function load({document.getElementById(\"yt\").play();}\</script>\</head><body onload=\"load()\"style=\"margin:0\">\<video id=\"yt\" src=\"%@\" \width=\"%0.0f\" height=\"%0.0f\" autoplay controls></video>\</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, videoView.frame.size.width, videoView.frame.size.height,thumbnailImageLink];
[videoView loadHTMLString:html baseURL:nil];

它工作得很好。它显示带有播放按钮的缩略图视频。点击“播放”按钮可在全屏模式下使用所有控件打开视频播放器。

现在主要的问题是 当我按下完成按钮时,全屏模式消失了嗯,这是预期的

但是视频的下载仍在继续。 一点都不好

所以说, 我打开了视频 1,然后按下完成按钮,然后我打开了视频 2 但是因为视频 1 仍在下载,视频 2 的网速变慢了。

所以问题是,有没有办法在全屏按下完成按钮时强行停止下载?

注意:有一个视频列表,即 n 个视频 = n 个 webviews 因此无法检测哪个 webview 正在播放视频。如果我能够访问 webview,那么我会重新加载它,这样下载就可以停止,它会获取新的内容,这些内容在我点击缩略图之前不会开始。

更具体地说,我可以访问何时播放视频以及何时按下“完成”按钮

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayFinished:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];

并且可以通过

访问
BOOL isVideoInFullScreenMode;
-(void)videoPlayStarted:(NSNotification *)notification{
//Your stuff here
   isVideoInFullScreenMode = YES;
}

-(void)videoPlayFinished:(NSNotification *)notification{
    //Your stuffs here
    isVideoInFullScreenMode = NO;
}

最佳答案

您无法控制 WebView 中发生的事情。 我认为这是一个设计问题。 Webviews 并不是万灵药。如果你想控制它,你需要自己编写代码。 我也希望你已经用 apple (http://bugreporter.apple.com) 解决了这个问题。

关于iphone - 通过 HTML 打开的全屏播放器即使按下完成也不会停止下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12689421/

相关文章:

iphone - iOS:旋转 iPhone 后,直接从仅支持纵向模式的 View Controller 以横向方式呈现 View Controller

ios - "Binary operator ' ~= ' cannot be applied to operands of type '

iphone - 使用 Audio Toolbox 播放 .wav

html - TextArea在div中填充剩余高度

iphone - iOS:使用 CLLocationManager 获得准确的反向地理编码?

iphone - 检测应用程序是否在 iOS 测试版上运行?

javascript - 从 ng-repeat 填充卡片

html - 不会并排放置表格的流畅的两列表格布局

iphone - 如何在运行时将一行插入 iPhone 上的 UITableView?

ios - 无法从另一个 View Controller 获取 TableView 数据