1

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

我在应用程序委托中的代码是

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];
}

我的应用程序在下一个崩溃..

4

1 回答 1

1

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

我不知道为什么,但是在尝试加载下一个或上一个视频时,与应用程序loadWithVideoId中的下一个和上一个按钮一起使用会崩溃。MPRemoteCommandCenter

所以我改变了loadWithVideoIdloadPlaylistByVideos似乎正在工作。在您的情况下,您可以尝试:

首先,PlayerView使用 playerVars 初始化:

NSDictionary *playerVars = @{
                             @"controls" : @1,
                             @"playsinline" : @1,
                             @"autohide" : @1,
                             @"modestbranding" : @1,
                             @"showinfo" : @1
                             };

[self.playerView loadWithPlayerParams:playerVars];

然后使用以下方法加载视频loadPlaylistByVideos

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

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

[self.playerView previousVideo];

或者

[self.playerView nextVideo];

希望能帮助到你!

于 2016-05-24T08:37:02.543 回答