完成:您可以通过此获取完成功能onPlayerStateChange(事件)的状态,再次调用player.play()正常工作
我需要在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 OUTPUT
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