完了:これにより完了関数 onPlayerStateChange(event) のステータスを取得し、 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 Stopped after First Video Completed And How Can I handle MediaPlayer Class で、MediaPlayer をもう一度再起動できます