Want next and previous button in my YTPlayerView while locked iPhone
Asked Answered
M

1

1

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.

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..

Medico answered 14/9, 2015 at 12:12 Comment(3)
did you find a solution for this?Equable
i created just play and pause button on locked screen , hides next and previous on locked screenMedico
ey @Jagveer Singh take a look at my solution, maybe it can helps you!Equable
E
1

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

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.

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

First, init the PlayerView with the playerVars:

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

[self.playerView loadWithPlayerParams:playerVars];

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

or

[self.playerView nextVideo];

Hope it helps!

Equable answered 24/5, 2016 at 8:37 Comment(1)
thnks for help buddy. i am quite busy , will later check that codeMedico

© 2022 - 2024 — McMap. All rights reserved.