1
votes

Currently I am making an iOS app which involves playing YouTube videos. I chose to use the official YouTube iOS Player Helper, which provides a mechanism to play YouTube videos with an URL.

Since the appearance which came with it did not fit the application's theme, I decided to load the thumbnails in a UIImageView and add a hidden YTPlayerView at the centre of the image view. (I can't grant that this is the cause of the problem)

However, here comes a problem: whenever I pause the video, unlike playing videos in Safari, the video turns blank, but it continues to play normally after I hit play again. Sometimes(rarely) my videos will start off with a blank screen with sound, but after a pause and a play, graphic comes back.

Info might be helpful to solve this problem:

  1. I have created a singleton class where there's a function which accepts two parameters: videoID: String and onView: UIView. There is a stored property player: YTPlayerView declared, and whenever user quits the full screen mode, this player property is immediately set to another YTPlayerView instance, just to let ARC to destroy the old one so that it doesn't conflict with my music player in MPNowPlayingCenter any more.

  2. On a simulator, but not a real device, all videos are immediately paused after first opened and started playing (I monitored the player state using delegate). After that pause, no more automatic pauses, but the issue described above still exists.

1
Do you mean to not use the official library instead to use another one? I would be glad to know which library are you currently using in your project. Thanks @MaulikNicholas
check my answerMaulik shah
Sorry, I made a typo. I was to say 'so that it doesn't conflict', see my edits. @halferNicholas

1 Answers

1
votes

I just stumbled across someone who was able to place a YouTube video inside an MPMoviePlayerController. It does appear possible now.

HCYoutubeParser

You can use this third party in swift.you can bridging in swift.