Want the next and previous button in my YTPlayerView when iPhone is locked

I need the next and previous button in my YTPlayerView, while the iPhone iOS is locked, in fact, when I use the next and previous button in the simulator, it works well, but when I press the next button when the iPhone is locked, then it crashes , I am using YTPlayerView in my application.

My code in application delegate

NSError *setCategoryError = nil; [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError]; [MPRemoteCommandCenter sharedCommandCenter].playCommand.enabled = YES; //comment below hide next and previous MPRemoteCommandCenter *rcc = [MPRemoteCommandCenter sharedCommandCenter]; MPRemoteCommand *nextTrackCommand = [rcc nextTrackCommand]; [nextTrackCommand setEnabled:YES]; [nextTrackCommand addTarget:self action:@selector(nextTrackCommandAction)]; // Doesn't show unless nextTrack is enabled MPRemoteCommand *previousTrackCommand = [rcc previousTrackCommand]; [previousTrackCommand setEnabled:YES]; [previousTrackCommand addTarget:self action:@selector(previousTrackCommandAction)]; -(void)nextButtonMethod{ NSDictionary *playerVars = @{ @"controls" : @1, @"playsinline" : @1, @"autohide" : @1, @"modestbranding" : @1, @"showinfo" : @1 }; [[YTPlayerInstance instance] loadWithVideoId:@"LlrY456zAMU" playerVars:playerVars]; } 

My application is broken down into the following.

+1
ios youtube-api iframe ytplayerview
Sep 14 '15 at 12:12
source share
1 answer

I also got into this problem, and maybe here is a possible solution.

I don’t know why, but with loadWithVideoId used with the next and previous buttons in MPRemoteCommandCenter , the application crashes when I try to load the next or previous video.

So, I changed loadWithVideoId to loadPlaylistByVideos and it seems to work. In your case, you can try:

Start up PlayerView with playerVars first:

 NSDictionary *playerVars = @{ @"controls" : @1, @"playsinline" : @1, @"autohide" : @1, @"modestbranding" : @1, @"showinfo" : @1 }; [self.playerView loadWithPlayerParams:playerVars]; 

And then upload the video using the loadPlaylistByVideos method:

 [self.playerView loadPlaylistByVideos:@[@"LlrY456zAMU"] index:0 startSeconds:0 suggestedQuality:kYTPlaybackQualityMedium]; 

Finally, to load the next or previous video, call the methods:

 [self.playerView previousVideo]; 

or

 [self.playerView nextVideo]; 

Hope this helps!

+1
May 24 '16 at 8:37 a.m.
source share



All Articles