Search code examples
androidandroid-youtube-api

Play youtube video in background


I am developing an Android app that suggests the most viewed videos clips in youtube, to play videos I am using the Youtube API for Android:

  @Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {

    Log.d(TAG , "onInitializationSuccess(Provider, YouTubePlayer, boolean ) - Ini ");

    if(!b) {
        youTubePlayer.cueVideo(getIntent().getStringExtra("VIDEO_ID"));
    }

    Log.d(TAG , "onInitializationSuccess(Provider, YouTubePlayer, boolean ) - Fi ");

}

I would like to add an other feature to the app, I want to detect if the user is looking to the screen if not, I want to send the video to the background and keep playing the music, is this possible ?

Any help is very much appreciated.


Solution

  • It's only to youtube red users possible to play youtube videos in background (see here). You can check if they have this in the api, but I don't think so.

    Also it is possible to play youtube videos in background if you open the desktop version of youtube in a browser. Maybe you can make use of this by opening the correct link in a webview in background ;-) ...