I've been trying to get YouTube music videos to play in my iOS app in a small window (not full screen) and can't get it to work. I've tried the following:
- I first used the YouTube API and created a YTPlayerView as instructed here: https://developers.google.com/youtube/v3/guides/ios_youtube_helper#adding_ytplayerview. This allowed me to play videos in-line, but many videos were unable to be played because of licensing issues, stating
"This video contains content from *. It is restricted from playback on certain sites."
- I then tried using a UIWebView, which successfully played the music videos that were previously unavailable. However, these videos were always forced to play in fullscreen mode, even when I set
webView.allowsInlineMediaPlayback = YES;
- I also tried embedding the video using the technique discussed here: How to embed YouTube video on iOs and play it directly on UIWebview without full screen. This worked to keep videos inline, but again, rendered certain videos unplayable.
- I finally tried using an MPMoviePlayerController, but later found out that it can't actually play YouTube videos, as we don't have access to the direct links of video files, so this was another no-go.
Apps like PingTune were clearly able to figure this out using YouTube - they are able to play YouTube music videos in a custom, non-fullscreen view and without ads - what am I missing? Is there a part of the YouTube API that allows me to play these music videos that I implemented incorrectly?
I've never tried it myself but you could try LBYouTubeView by Laurin Brandner. LBYouTubeView is just a small view that is able to display YouTube videos in a MPMoviePlayerController. You even have the choice between high-quality and standard quality stream.
Code sample