安卓4.2+浏览器全屏播放cntv在线视频(直播)时不能显示画面的问题
2013 年 9 月 11 日 安卓4.2+浏览器全屏播放cntv在线视频(直播)时不能显示画面的问题无评论
问题出现的原因是在处理cntv的m3u8流媒体时底层的视频解码出错,底层对这种流媒体支持的不是很好。但是在凤凰测试这种视频时(网页显示为iphone端,android端为rtsp流会走图库播放)却会调用图库播放。可以在html页面中增加如下html5 video标签测试:
<html>
<title>video test</title>
<body>
<video src="http://tvhd.cc.live.cntv.cn/cache/1_/seg0/index.m3u8?AUTH=st%3D1378870709%7Eexp%3D1378957109%7Eacl%3D%2F*%7Ehmac%3D8e548882e852fb9d3ba66b50c72583dda0a0da3a4bbe870564031b9a063db715" controls=""></video>
<!--
<video style="margin: 10px auto; position: relative; width: 320px; height: 280px;" src="1.mp4" controls=""></video>
-->
<video src="1.mp4" controls=""></video>
</body>
</html>
<title>video test</title>
<body>
<video src="http://tvhd.cc.live.cntv.cn/cache/1_/seg0/index.m3u8?AUTH=st%3D1378870709%7Eexp%3D1378957109%7Eacl%3D%2F*%7Ehmac%3D8e548882e852fb9d3ba66b50c72583dda0a0da3a4bbe870564031b9a063db715" controls=""></video>
<!--
<video style="margin: 10px auto; position: relative; width: 320px; height: 280px;" src="1.mp4" controls=""></video>
-->
<video src="1.mp4" controls=""></video>
</body>
</html>
修正方法:
由于这种流媒体在当前的mediaplayer释放后重新加载可以继续播放,具体的处理在frameworks/base/core/java/android/webkit/HTML5VideoViewProxy.java
修正代码如下:
diff --git a/HTML5VideoViewProxy.java b/HTML5VideoViewProxy.java
index a3d62ae..87584eb 100755
--- a/HTML5VideoViewProxy.java
+++ b/HTML5VideoViewProxy.java
@@ -167,11 +167,22 @@ class HTML5VideoViewProxy extends Handler
|| playerState == HTML5VideoView.STATE_PLAYING;
}
}
+ // Begin: [ty, 2013-09-10] Add for cntv live video @{
+ String cntv = "tvhd.cc.live.cntv.cn";
+ if (mHTML5VideoView != null && url.contains(cntv)) {
+ mHTML5VideoView.release();
+ }
+ // End: [ty, 2013-09-10] Add for cntv live video @}
mHTML5VideoView = new HTML5VideoFullScreen(proxy.getContext(),
layerId, savePosition, canSkipPrepare);
mHTML5VideoView.setStartWhenPrepared(forceStart);
mCurrentProxy = proxy;
mHTML5VideoView.setVideoURI(url, mCurrentProxy);
+ // Begin: [ty, 2013-09-10] Add for cntv live video @{
+ if (url.contains(cntv)) {
+ mHTML5VideoView.reprepareData(proxy);
+ }
+ // End: [ty, 2013-09-10] Add for cntv live video @}
mHTML5VideoView.enterFullScreenVideoState(layerId, proxy, webView);
}
@@ -236,6 +247,20 @@ class HTML5VideoViewProxy extends Handler
createInlineView = true;
}
if (createInlineView) {
+ // Begin: [ty, 2013-09-11] Add for fullscreen live video @{
+ String cntv = "tvhd.cc.live.cntv.cn";
+ if (mHTML5VideoView != null && url.contains(cntv) && backFromFullScreenMode) {
+ mCurrentProxy = proxy;
+ mHTML5VideoView.pauseAndDispatch(mCurrentProxy);
+ mHTML5VideoView.pause();
+ mHTML5VideoView.reset();
+ mHTML5VideoView = new HTML5VideoInline(videoLayerId, time, false);
+ mHTML5VideoView.setStartWhenPrepared(true);
+ mHTML5VideoView.setVideoURI(url, mCurrentProxy);
+ mHTML5VideoView.prepareDataAndDisplayMode(proxy);
+ return;
+ }
+ // End: [ty, 2013-09-11] Add for fullscreen live video @}
mCurrentProxy = proxy;
mHTML5VideoView = new HTML5VideoInline(videoLayerId, time, skipPrepare);
index a3d62ae..87584eb 100755
--- a/HTML5VideoViewProxy.java
+++ b/HTML5VideoViewProxy.java
@@ -167,11 +167,22 @@ class HTML5VideoViewProxy extends Handler
|| playerState == HTML5VideoView.STATE_PLAYING;
}
}
+ // Begin: [ty, 2013-09-10] Add for cntv live video @{
+ String cntv = "tvhd.cc.live.cntv.cn";
+ if (mHTML5VideoView != null && url.contains(cntv)) {
+ mHTML5VideoView.release();
+ }
+ // End: [ty, 2013-09-10] Add for cntv live video @}
mHTML5VideoView = new HTML5VideoFullScreen(proxy.getContext(),
layerId, savePosition, canSkipPrepare);
mHTML5VideoView.setStartWhenPrepared(forceStart);
mCurrentProxy = proxy;
mHTML5VideoView.setVideoURI(url, mCurrentProxy);
+ // Begin: [ty, 2013-09-10] Add for cntv live video @{
+ if (url.contains(cntv)) {
+ mHTML5VideoView.reprepareData(proxy);
+ }
+ // End: [ty, 2013-09-10] Add for cntv live video @}
mHTML5VideoView.enterFullScreenVideoState(layerId, proxy, webView);
}
@@ -236,6 +247,20 @@ class HTML5VideoViewProxy extends Handler
createInlineView = true;
}
if (createInlineView) {
+ // Begin: [ty, 2013-09-11] Add for fullscreen live video @{
+ String cntv = "tvhd.cc.live.cntv.cn";
+ if (mHTML5VideoView != null && url.contains(cntv) && backFromFullScreenMode) {
+ mCurrentProxy = proxy;
+ mHTML5VideoView.pauseAndDispatch(mCurrentProxy);
+ mHTML5VideoView.pause();
+ mHTML5VideoView.reset();
+ mHTML5VideoView = new HTML5VideoInline(videoLayerId, time, false);
+ mHTML5VideoView.setStartWhenPrepared(true);
+ mHTML5VideoView.setVideoURI(url, mCurrentProxy);
+ mHTML5VideoView.prepareDataAndDisplayMode(proxy);
+ return;
+ }
+ // End: [ty, 2013-09-11] Add for fullscreen live video @}
mCurrentProxy = proxy;
mHTML5VideoView = new HTML5VideoInline(videoLayerId, time, skipPrepare);
同时修改HTML5VideoFullScreen.java文件以适应停止、继续功能。修改如下所示:
diff --git a/HTML5VideoFullScreen.java b/HTML5VideoFullScreen.java
index b52218d..67efb3d 100755
--- a/HTML5VideoFullScreen.java
+++ b/HTML5VideoFullScreen.java
@@ -207,6 +207,12 @@ public class HTML5VideoFullScreen extends HTML5VideoView
|| data.getBoolean(Metadata.SEEK_BACKWARD_AVAILABLE);
mCanSeekForward = !data.has(Metadata.SEEK_FORWARD_AVAILABLE)
|| data.getBoolean(Metadata.SEEK_FORWARD_AVAILABLE);
+ // Begin: [ty, 2013-09-11] Add for cntv live video @{
+ String cntv = "tvhd.cc.live.cntv.cn";
+ if (mUri != null && mUri.toString().contains(cntv)) {
+ mCanPause = true;
+ }
+ // End: [ty, 2013-09-11] Add for cntv live video @}
} else {
mCanPause = mCanSeekBack = mCanSeekForward = true;
}
index b52218d..67efb3d 100755
--- a/HTML5VideoFullScreen.java
+++ b/HTML5VideoFullScreen.java
@@ -207,6 +207,12 @@ public class HTML5VideoFullScreen extends HTML5VideoView
|| data.getBoolean(Metadata.SEEK_BACKWARD_AVAILABLE);
mCanSeekForward = !data.has(Metadata.SEEK_FORWARD_AVAILABLE)
|| data.getBoolean(Metadata.SEEK_FORWARD_AVAILABLE);
+ // Begin: [ty, 2013-09-11] Add for cntv live video @{
+ String cntv = "tvhd.cc.live.cntv.cn";
+ if (mUri != null && mUri.toString().contains(cntv)) {
+ mCanPause = true;
+ }
+ // End: [ty, 2013-09-11] Add for cntv live video @}
} else {
mCanPause = mCanSeekBack = mCanSeekForward = true;
}
代码见附件:
Tags: android webkit 安卓 直播 视频
发表评论