Done : you can get the status of completion function onPlayerStateChange(event) by this and player.play() call again Working fine
I need to play Youtube video in WEBView and also need to playlist . So, I am using YTPlayer for this.
In 4.3 and 4.4 version Playlist working fine but in the below version only first video id is playing after completition of the first video next video id which is in the playlist does not play
I have been search some things which I found in LOGCAT : HTML5VideoViewProxy.java this class called and got message ENDED / PAUSE which I mentioned in LOGCAT detail.
Why 4.3 / 4.4 version not having any issue but in the other side below these version.
Please have a look on this matter ????
<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>
the above content is in youtube.html file and handle this file through this way
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();
}
Problem
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
Does any setting will needed for 4.0, 4.1 ,4.2 for the webView ???
EDIT for logcat OUTPUT when the Video Completed
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()
In the LogCat MediaPlayer Stopped after First Video Completed And How Can I handle MediaPlayer Class , So I can Restart the MediaPlayer Again