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

だから私はに変更し、loadWithVideoId動作しloadPlaylistByVideosているようです。あなたの場合、あなたは試すことができます:

まず、PlayerViewplayerVarsで を初期化します。

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 に答える