MPMoviePlayerController does not remove view when clicking done

删除回忆录丶 提交于 2019-12-05 05:33:28
Sirji

The below code worked for me, Hope it helps you too.

-(IBAction)playVedio:(id)sender{
mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

    [[mp moviePlayer] prepareToPlay];
    [[mp moviePlayer] setUseApplicationAudioSession:NO];
    [[mp moviePlayer] setShouldAutoplay:YES];
    [[mp moviePlayer] setControlStyle:2];
    [[mp moviePlayer] setRepeatMode:MPMovieRepeatModeOne];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    [self presentMoviePlayerViewControllerAnimated:mp];

}

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

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

    [mp.moviePlayer stop];
    mp = nil;
    [mp release];
    [self dismissMoviePlayerViewControllerAnimated];  
}
Vishnuvardhan Sadu
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    id presentedViewController = [window.rootViewController presentedViewController];
    NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;

    if (window && [className isEqualToString:@"AVFullScreenViewController"]) {

        return UIInterfaceOrientationMaskAll;

    } else {

        UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;

        if(UIInterfaceOrientationIsPortrait(interfaceOrientation))

        {

        }

        else if(UIInterfaceOrientationIsLandscape(interfaceOrientation))

        {


        }

        return UIInterfaceOrientationMaskPortrait;

        CGRect frame = [UIScreen mainScreen].applicationFrame;
        CGSize size = frame.size;
        NSLog(@"%@", [NSString stringWithFormat:@"Rotation: %s [w=%f, h=%f]",
                      UIInterfaceOrientationIsPortrait(interfaceOrientation) ? "Portrait" : "Landscape",
                      size.width, size.height]);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!