完成:您可以通过此和 player.play() 再次调用获得完成功能 onPlayerStateChange(event) 的状态工作正常
我需要在 WEBView 中播放 Youtube 视频,还需要播放列表。所以,我为此使用 YTPlayer。
在 4.3 和 4.4 版本播放列表工作正常,但在以下版本中,只有第一个视频 id 在第一个视频完成后播放,播放列表中的下一个视频 id 不播放
我一直在搜索我在 LOGCAT 中找到的一些东西: HTML5VideoViewProxy.java这个类调用并得到了我在 LOGCAT 详细信息中提到的消息 ENDED / PAUSE。
为什么 4.3 / 4.4 版本没有任何问题,但在这些版本下面的另一边。
请看看这个问题????
<html>
<head><style>body{margin:0px 0px 0px 0px;}</style></head>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player',
{
height: '100%',
width: '100%',
videoId: '%@',
playerVars:
{'version':3, 'autoplay': 1,'showinfo':1, 'controls': 2,'autohide':1,'wmode':'opaque','loop':1,'playlist':'%@'},
events:
{
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
} });
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event)
{
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
// var playerstatus='stop';
function onPlayerStateChange(event)
{
if (event.data == YT.PlayerState.PLAYING && !done)
{
done = true;
}
}
</script>
</form>
</body>
</html>
以上内容在youtube.html文件中,通过这种方式处理这个文件
try {
InputStream is = getAssets().open("youtube.html");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String str = new String(buffer);
str = str.replace("videoId: '%@'", "videoId: '"+video_id+"'");
str = str.replace("'playlist':'%@'", "'playlist':'"+playlist+"'");
String mime = "text/html";
String encoding = "utf-8";
engine.getSettings().setJavaScriptEnabled(true); // engine is id of WEBView
engine.loadDataWithBaseURL(null, str, mime, encoding, null);
} catch (Exception e) {
e.printStackTrace();
}
问题
First video running fine but when the first video completed. I am using loop in the YTplayer but the next video does not play automatically in 4.0,4.1,4.2 verson
In other side in Nexus 7 (4.3 and 4.4 version) next video automatically run successfully
webView 4.0、4.1、4.2 是否需要任何设置?
视频完成时编辑 logcat 输出
04-10 16:45:55.839: V/MediaPlayer(24581): isPlaying: 1
04-10 16:45:55.979: V/MediaPlayer(24581): isPlaying: 1
04-10 16:45:56.019: V/MediaPlayer(24581): isPlaying: 1
04-10 16:45:56.119: V/MediaPlayer(24581): message received msg=2, ext1=0, ext2=0
04-10 16:45:56.119: V/MediaPlayer(24581): playback complete
04-10 16:45:56.119: V/MediaPlayer(24581): callback application
04-10 16:45:56.119: V/MediaPlayer(24581): back from callback
04-10 16:45:56.139: I/MediaPlayer(24581): mOnCompletionListener. Send MEDIA_PLAYBACK_COMPLETE message.
04-10 16:45:56.139: V/MediaPlayer(24581): isPlaying: 0
04-10 16:45:56.169: D/HTML5VideoViewProxy(24581): handleMessage : ENDED
04-10 16:45:56.209: V/MediaPlayer(24581): isPlaying: 0
04-10 16:45:56.209: D/HTML5VideoViewProxy(24581): handleMessage : PAUSE
04-10 16:45:56.249: D/HTML5VideoViewProxy(24581): teardown()
04-10 16:45:56.249: V/MediaPlayer(24581): stop
04-10 16:45:56.249: V/MediaPlayer(24581): setListener
04-10 16:45:56.249: V/MediaPlayer(24581): disconnect
04-10 16:45:56.289: V/MediaPlayer(24581): destructor
04-10 16:45:56.289: V/MediaPlayer(24581): disconnect
04-10 16:45:56.289: D/HTML5VideoViewProxy(24581): teardown() : release()
在第一个视频完成后 LogCat MediaPlayer 停止以及如何处理 MediaPlayer 类,所以我可以再次重新启动 MediaPlayer