Android YouTube API video pause when rotate screen or hide player

youtubeplayersupportfragment androidx
embed config is not supported in remoteembeddedplayer.
play youtube video in android application example
play youtube video in popup window android
embed youtube video in android app
android play video from youtube url
android-youtube player full screen
youtube player methods

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!


When you flip the screen, the activity that was playing the video gets destroyed, and a new activity gets created with everything reset. Its a feature, not a bug. :)

There are a handful of ways of dealing with this; you will probably have to save off some state and then check for any saved data when any new activity gets created, manage the data, etc. Check out: Keeping data view/layout in Android after screen rotate/activity destroyed.

Android YouTube API video pause when rotate screen or hide player?, When you flip the screen, the activity that was playing the video gets destroyed, and a new activity gets created with everything reset. Its a feature, not a bug. :). Using the API, you can load or cue videos into a player view embedded in your application's UI. You can then control playback programmatically. For example, you can play, pause, or seek to a specific point in the currently loaded video. You can also register event listeners to get callbacks for certain events, such as the player loading a video


What did the trick for me is to add:

android:configChanges="keyboardHidden|orientation|screenSize"

to your android manifest.

Cheers..

YouTubePlayer | YouTube Android Player API, There is one approach that enables the video to play without any pauses during device rotation. Check out the YouTubeStandalonePlayer createVideoIntent()  5 Android YouTube API video pause when rotate screen or hide player Feb 25 '15 5 Android: why does Checkbox not show empty checkbox for unchecked state? Feb 9 '18


<activity 
android:label="YoursActivityName" 
android:configChanges="keyboardHidden|orientation|screenSize"
android:name="com.example.naren.YoursActivityName" /> 

Add it in yours manifest file.

Using the YouTube API to Embed Video in an Android App, Javadoc API documentation for YouTube Android Player API. Stop any loading or video playback and release any system resources used by this YouTubePlayer . Note that setting this flag will always cause the screen orientation of Otherwise, it will be hidden for the duration of the fullscreen session. It made watching videos on YouTube a bit annoying. If you are also facing this issue, I will help you get rid of it. You won’t have to press the X mark to hide the screen controls. Let’s get


There is one approach that enables the video to play without any pauses during device rotation. Check out the YouTubeStandalonePlayer createVideoIntent() API with 'lightboxMode' parameter set to true.

If it is set to true, it plays the video in a dialog view above your current Activity and does not pause during device rotations.

CUSTOM FULLSCREEN YOUTUBE ANDROID PLAYER, The YouTube Android Player API enables you to incorporate video playback functionality For example play, pause, or seek to a specific point in the loaded video. Select the Empty Activity template on the next window and  The official library provided by Google to integrate YouTube videos in Android apps is the YouTube Android Player API. The official library is quite buggy ( some bugs are 5+ years old ) and lacks in support from Google.


add player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT)

    override fun onInitializationSuccess(provider: YouTubePlayer.Provider, player: YouTubePlayer, wasRestored: Boolean) {
        player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT)
        if (!wasRestored) {
            player.loadVideo(videoId)
        }
    }

document https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayer#FULLSCREEN_FLAG_CUSTOM_LAYOUT

avoiding the rebuffering that occurs in the default fullscreen behavior

How to hide "more videos" row when video paused? · Issue #226 , CUSTOM FULLSCREEN YOUTUBE ANDROID PLAYER the video timings as the Minimal Duration: 15:01 Posted: Dec 5, 2017 The API will call the onPlayerStateChange function when the player's state changes, which may indicate that the player is playing, paused, finished, and so forth. The function indicates that when


Exoplayer hide controls, This library is built on top of the web version of the YouTube player. notes of the IFrame API, as expected they made changes to the player :/ How To Rotate Video on Android Theandroidportal. you can pause the video. When you tap on the screen, the video controls will load. Rotate and Save Video in VLC Media Player - Duration:


Video, API level 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1. control over screen orientation in every moment, even if the user disabled auto-rotate. ExoPlayer is the video player running in the Android YouTube app. pause, and so on) that they did not exist, and the screen was always full. A list of YouTube video IDs to be cued, as returned from the YouTube Data API. startIndex: The index in the list of the first video to be cued. timeMillis: The time, in milliseconds, where playback should start in the first video cued.


How to turn off the auto-suggested videos that show up at the end of , Much of Video and Audio have common APIs that are documented in AV Setting this property to m3u8 would allow the Android player to properly infer display native playback controls (such as play and pause) within the Video component. Attach parameters to the Youtube iframe URL to modify its behaviour. We can make some changes to an embedded Youtube video's behavior just by attaching parameters to the end of the Youtube URL inside the iframe. The following for example causes the video to automatically play when it's loaded: