Save current Second & the Duration of the video when orientation change
See original GitHub issueHello,
I would like to ask you how can i setup the saved state of the current second and the duration of the video when an activity-fragment is re-created (orientation change). I use the onStateChange() to get the current second of the video and the video duration (and i’m storing them inside the onSaveInstanceState), but still when the orientation changes the video starts from 0 and after that is going to the saved current Video Second.
I tried to use youtubePlayer.seekTo(videoSecond) method to set the current second immediately, but without success…
Futhermore, i want to setup too the saved video Duration immediately when the orientation changes, but i can’t find the way…
Here is the method inside the Fragment:
private void initYouTubePlayerView() {
getLifecycle().addObserver(youtubePlayerView);
youtubePlayerView.initialize(youTubePlayer -> {
youTubePlayer.addListener(new AbstractYouTubePlayerListener() {
@Override
public void onReady() {
loadVideo(youTubePlayer, mSuggestionYoutubeId);
}
});
mTracker = new YouTubePlayerTracker();
youTubePlayer.addListener(mTracker);
youTubePlayer.addListener(new AbstractYouTubePlayerListener() {
@Override
public void onStateChange(@NonNull PlayerConstants.PlayerState state) {
super.onStateChange(state);
videoSecondFloat = mTracker.getCurrentSecond();
videoDuration = mTracker.getVideoDuration();
}
});
}, true);
fetchVideoTitle();
}
Here is the loadVideo Method:
private void loadVideo(YouTubePlayer youTubePlayer, String videoId) {
if(getLifecycle().getCurrentState() == Lifecycle.State.RESUMED)
youTubePlayer.loadVideo(videoId, videoSecondFloat);
else
youTubePlayer.cueVideo(videoId, videoSecondFloat);
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How To Save Activity's State When Orientation Changes in ...
In this quick android tutorial, we use onSaveInstanceState() and onRestoreInstanceState() methods in order to temporary save information.
Read more >When the orientation change from portrait to landscape, the ...
I am writing an Android project, at beginning I am playing a video in portrait mode, a few seconds later when i change...
Read more >Change or lock the screen orientation on iPhone
You can lock the screen orientation so that it doesn't change when you rotate iPhone. Open Control Center, then tap the Lock Orientation...
Read more >Handling Orientation Changes on Android | Medium
The most important aspect of handling orientation changes is saving state. In most cases this involves implementing the onSaveInstanceState ...
Read more >Changing page orientation - Canva Help Center
Tap Resize to resize the current design. Depending on your design, you might be given the option to pick from two resized variations....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Nice!
Yes… I did that and it’s working…