在锁定iPhone时,想要我的YTPlayerView中的下一个和上一个按钮

我想要锁定iPhone iOS时我的YTPlayerView中的下一个和上一个按钮,实际上当我在模拟器中使用下一个和上一个按钮时效果很好,但是当我按下下一个按钮而iPhone被锁定然后它崩溃时,我在我的应用程序中使用YTPlayerView。

我在app 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]; } 

我的应用程序正在崩溃下..

我也陷入了这个问题,也许这里是一个可能的解决方案。

我不知道为什么但是当使用loadWithVideoIdloadWithVideoId下一个和上一个按钮一起MPRemoteCommandCenter ,应用程序在尝试加载下一个或上一个video时崩溃。

所以我将loadWithVideoId更改为loadPlaylistByVideos并且似乎正在工作。 在你的情况下你可以尝试:

首先,使用PlayerView初始化PlayerView:

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

然后使用loadPlaylistByVideos方法加载video:

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

最后加载下一个或上一个video调用方法:

 [self.playerView previousVideo]; 

要么

 [self.playerView nextVideo]; 

希望能帮助到你!