- 注1:这个问题指的是
仅限 HTML5 视频,不适用于 Flash 视频。
- 注2:另外,它特别
目标 HTML5 视频播放
安卓。
鉴于 YouTube 中的以下 HTML5 视频:
<div id="player">
<video poster="data:image/gif;
base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
src="http://v19.lscache2.c.youtube.com/videoplayback?begin=0&itag=18&
ipbits=0ampsignature=151700E49EA1B695940D89926C1C07CDF0C176F0.B7DE0453C70BFBA0BA644DE7F6BBB72E9EE43B5F&
sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Cratebypass%2Coc%3AU0hPSVRSUl9FSkNOOV9MTFZF&
sver=3&
ratebypass=yes&expire=1304474400&len=265000&key=yt1&ip=0.0.0.0&
id=55884c15b4baba8f&el=home&yms=5602568839599417322&app=youtube_mobile" class="bn" width="1" height="2" id="player_VYhMFbS6uo8">
</video>
</div>
我可以将 src=
属性识别为正在加载到的 URL...到底是什么?
我知道 WebView 本身无法播放 HTML5 视频,所以它将它们交给 WebChromeClient:当我触摸< /strong> 熟悉的图像中间的向右箭头代表剪辑时,Android 会自动切换到播放视频的不同 Activity,而不是在 WebView 中播放。
现在,我想开始以完全相同的方式播放视频,但在我的应用程序中,无需用户必须“单击”向右箭头。
我试图简单地交出该 src=
URL ( http://v19.lscache2.c.youtube.com/videoplayback?begin...) 到 WebView,认为这会触发 WebChromeClient.onShowCustomView()
就像当我点击向右箭头时会发生什么,但是...当我这样做时,实际上什么也没有发生。
所以,我想知道:从 WebView
和 WebChromeClient
的角度来看,当我单击 向右箭头?
我需要做什么才能“单击”右指箭头?
更新:感谢@dronus 的评论,我在 LogCat 中发现了以下内容(手动点击播放按钮后):
05-03 19:35:07.296: INFO/StagefrightPlayer(121):
setDataSource('http://v19.lscache2.c.youtube.com/videoplayback?begin=0
&itag=18
&ipbits=0
&signature=BB85C25344502EF07EC970250EFBF6661098373E.6A7E108FA6F48A0741CDF7A356B0E1474F185195
&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Cratebypass%2Coc%3AU0hPSVRTVl9FSkNOOV9MTVpJ
&sver=3
&ratebypass=yes
&expire=1304488800
&len=265000
&key=yt1
&ip=0.0.0.0
&id=55884c15b4baba8f
&el=watch
&yms=5602637908081220405
&app=youtube_mobile')
问题仍然存在:是什么触发了这个?
- Note 1: This question refers to
HTML5 videos only, not Flash videos.
- Note 2: Also, it specifically
targets HTML5 video playing on
Android.
Given the following HTML5 video in YouTube:
<div id="player">
<video poster="data:image/gif;
base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
src="http://v19.lscache2.c.youtube.com/videoplayback?begin=0&itag=18&
ipbits=0ampsignature=151700E49EA1B695940D89926C1C07CDF0C176F0.B7DE0453C70BFBA0BA644DE7F6BBB72E9EE43B5F&
sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Cratebypass%2Coc%3AU0hPSVRSUl9FSkNOOV9MTFZF&
sver=3&
ratebypass=yes&expire=1304474400&len=265000&key=yt1&ip=0.0.0.0&
id=55884c15b4baba8f&el=home&yms=5602568839599417322&app=youtube_mobile" class="bn" width="1" height="2" id="player_VYhMFbS6uo8">
</video>
</div>
I can identify the src=
attribute as a URL being loaded into... what exactly?
I know that WebView can't play HTML5 videos by itself, so it hands them over to WebChromeClient: When I touch that familiar right-pointing arrow in the middle of the image representing the clip, Android switches automatically to a different activity that plays the video, instead of playing it inside WebView.
Now, I would like to start playing the video in exactly the same manner but from within my app, without the user having to "click" that right-pointing arrow.
I tried to simply hand over that src=
URL (http://v19.lscache2.c.youtube.com/videoplayback?begin...) to WebView, thinking that this would trigger WebChromeClient.onShowCustomView()
just as what happens when I click the right-pointing arrow, but... nothing really happens when I do that.
So, I am wondering: What actually happens, from WebView
and WebChromeClient
point of view, when I click that right-pointing arrow?
What do I need to do in order to "click" that right-pointing arrow?
Update: Thanks to the comment from @dronus I found the following in LogCat (after clicking the play button manually):
05-03 19:35:07.296: INFO/StagefrightPlayer(121):
setDataSource('http://v19.lscache2.c.youtube.com/videoplayback?begin=0
&itag=18
&ipbits=0
&signature=BB85C25344502EF07EC970250EFBF6661098373E.6A7E108FA6F48A0741CDF7A356B0E1474F185195
&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Cratebypass%2Coc%3AU0hPSVRTVl9FSkNOOV9MTVpJ
&sver=3
&ratebypass=yes
&expire=1304488800
&len=265000
&key=yt1
&ip=0.0.0.0
&id=55884c15b4baba8f
&el=watch
&yms=5602637908081220405
&app=youtube_mobile')
The question remains: What triggers this?
发布评论
评论(1)
我猜测会启动一个 Intent 来显示具有指定 url 和所有其他属性的视频。
您是否尝试过启动这样的意图,并将某些属性列为该意图的附加属性?
I would guesss that an Intent is launched to display the video with the specfied url and all other attributes.
Have you tried to launch an Intent like this with some of the attributes listed as extras for the intent?