Search code examples
androidandroid-youtube-api

Play a Youtube video in a fragment


I am working on an app. This app uses a Master-/Detail-View.

After selecting an video in the Master-View I want to play a video in the Detail-View. Currently I focus on the tablet version, which means, I want to play a yt-video in the detail-fragment.

How can I do this?

//edit: The default code uses getSupportFragmentManager() and I tried to put a normal YouTubePlayerFragment. Either use getFragmentManager() or use YouTubePlayerSupportFragment. This fixed my issue.


Solution

  • The youtube API provides the YoutubePlayerFragment to play youtube video in a fragment.

    Also, Youtube API provides the YouTubePlayerSupportFragment based on android.support.v4.app.Fragment to earlier versions.

    Hope this helps!