开发者

iphone: how to stop playing video on click of 'Back' button?

开发者 https://www.devze.com 2023-03-17 16:57 出处:网络
I am trying to build the back button with functionality that on click of that button the video that is playing should stop.

I am trying to build the back button with functionality that on click of that button the video that is playing should stop. In my case it removes from the superview but the video is still playing in the background. I am doing as below but it is not working

    -(IBAction)backButtonPressed
        {
           [[NSNotificationCenter defaultCenter] addObserver:self         selector:@selector(movieDidExitFullScreen:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
            [self.navigationController popViewControllerAnimated:YES];
        }

- (void) movieDidExitFullScreen:(NSNotification*)notification 
{    

    [[NSNotificationCenter defaultCenter] remo开发者_运维百科veObserver: self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object: [notification object]];

    MPMoviePlayerController *theMovie1 = [notification object];

    [self.navigationController popViewControllerAnimated:YES];

    [theMovie1 release];
}


Replace your back button Action event to below.

-(IBAction)backButtonPressed
{
    [player stop];
    [player release];
    player =nil;
    [self.navigationController popViewControllerAnimated:YES];
}

This will stop player and release it before going back. Hope this help.


You're not actually stopping playback of the movie in that code, you're just removing the view that the video was displayed on. You set up the notification for when the video stops, so that movieDidExitFullScreen method won't be invoked until the video finishes playing. The easiest solution is to call [theMovie1 stop], but you need to somehow get access to the movie from within your backButtonPressed

0

精彩评论

暂无评论...
验证码 换一张
取 消