在锁定iPhone时,想要我的YTPlayerView中的下一个和上一个按钮 [英] Want next and previous button in my YTPlayerView while locked iPhone

查看:249
本文介绍了在锁定iPhone时,想要我的YTPlayerView中的下一个和上一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want next and previous button in my YTPlayerView while locked iPhone iOS, actually when I use next and previous button in simulator its works well, but when I press next button while iPhone is locked then its crashes, I am using YTPlayerView in my app.

我在app delegate中的代码是

My code in app delegate is

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 app is crashing on next..

推荐答案

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

I had fallen in this problem too and maybe here it is a possible solution.

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

I don't know why but with loadWithVideoId used with next and previous buttons in MPRemoteCommandCenter the app crashes when tries to load next or previous video.

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

So i changed the loadWithVideoId to loadPlaylistByVideos and seems to be working. In your case you could try:

首先,使用playerVars初始化 PlayerView

First, init the PlayerView with the playerVars:

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

[self.playerView loadWithPlayerParams:playerVars];

接下来用 loadPlaylistByVideos 方法加载视频:

And next load the videos with loadPlaylistByVideos method:

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

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

Finally to load next or previous videos call the methods:

[self.playerView previousVideo];

[self.playerView nextVideo];

希望有所帮助!

这篇关于在锁定iPhone时,想要我的YTPlayerView中的下一个和上一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆