jeudi 13 août 2015

iOS - MPMoviePlayer is not allowing to pause the video

I am working on MPMoviePlayerController.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *fileURL = [NSString stringWithFormat:@"%@/FileName.mp4", documentsDirectory];
myMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:fileURL]];
myMoviePlayer.backgroundView.backgroundColor = [UIColor blackColor];
[[myMoviePlayer view] setFrame:CGRectMake(0, 0, self.view.frame.size.width, getReadyMoviePlayerView.frame.size.height)];
[myMoviePlayerView addSubview:[myMoviePlayer view]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinished:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:myMoviePlayer];
myMoviePlayer.controlStyle = MPMovieControlStyleEmbedded;
myMoviePlayer.shouldAutoplay = NO;
myMoviePlayer.fullscreen = NO;
myMoviePlayer.repeatMode = MPMovieRepeatModeOne;
[myMoviePlayer prepareToPlay];
[myMoviePlayer play ];


-(void)moviePlayBackDidFinished:(NSNotification *)dict{

    if (dict.object == myMoviePlayer) {

        NSInteger reason = [[dict.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
        if (reason == MPMovieFinishReasonPlaybackEnded){

            [myMoviePlayer prepareToPlay];
            [myMoviePlayer play];
        }
    }
}

Now the problem is that, The play and pause button is not working. I am not able to pause the video by using MPMoviePlayer Controls.

This problem is with both OS that is iOS 7 and iOS 8 also.

Is there any solution to pause the running video.

Thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire