I'm using the YouTube API for Android. The video is playing normally but when I turn the screen, the player stop the video and it comes back from the beginning as if it had not been played. The same happens when scroll the screen and hides the player. I've researched a lot about and also got to test some things I found but nothing worked =(
This is the way that i declared my class:
public class PlayerTest extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {
This is what i put into onCreate():
YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(DEVELOPER_KEY, this);
and this is the methods what i implement:
@Override
public void onInitializationFailure(Provider provider,
YouTubeInitializationResult error) {
Toast.makeText(this, "Error :( " + error.toString(), Toast.LENGTH_LONG)
.show();
}
@Override
public void onInitializationSuccess(Provider provider,
YouTubePlayer player, boolean wasRestored) {
player.cueVideo(video);
}
question:
I want the video continue playing while scrolls or flips the screen. Is this possible? I'm implementing the right way? If not, what would be the best way?
Thank you in advance for help!
Activity
is destroyed and recreated when the device orientation changes. I suggest you use thegetCurrentTimeMillis()
method to find the current play position (perhaps in theActivity
onPause()
method) and save it, When theActivity
is recreated, use theseekToMillis()
method to restart playback at the last position. – Sletten