2

I am using YouTube API in my iOS application and the problem is that it loads really slow on my iPhone, but on iOS simulator it works perfectly.

I tried it on different networks and on different iPhones and its always the same. On every network simulator works a lot better.

I'm using YTPlayerView-iframe-player.html and YTPlayerView.

So, the question is can I do anything to load it faster or can I start playing song after it loads?

JAL
  • 41,701
  • 23
  • 172
  • 300
Nikola Klipa
  • 333
  • 3
  • 14

2 Answers2

2

There is no way to speed up your network. You can do two things to improve the user experience: hide the player until the video loads, and start playing the video as soon as possible (autoplay).

Add the autoplay key to your playervars dictionary:

NSDictionary *playerVars = @{
                             @"playsinline" : @1,
                             @"autoplay" : @1, // <- here
                             @"showinfo" : @0,
                             @"rel" : @0,
                             @"modestbranding" : @1,
                             };

[self.playerView loadWithVideoId:videoId playerVars:playerVars];

// hide the player view until it is ready
self.playerView.hidden = YES;

Unhide the player when ready:

// unhide and play
- (void)playerViewDidBecomeReady:(YTPlayerView *)playerView { 
    self.playerView.hidden = NO;
}

or

- (void)playerView:(YTPlayerView *)playerView didChangeToState:(YTPlayerState)state {
    if (state == kYTPlayerStatePlaying) {
        self.playerView.hidden = NO;
    }
}
JAL
  • 41,701
  • 23
  • 172
  • 300
1

Switch to using WKWebView instead of old UIWebView. Because WKWebView has support of native Safari Turbo JavaScript rendering engine, which I assume will make your iframe run faster.

Soberman
  • 2,556
  • 1
  • 19
  • 22
  • YTPlayerView is using UIView in storyboard, so is there any easy way to change everything or I have to change whole code? – Nikola Klipa Oct 10 '15 at 10:31