MPMoviePlayerController在BACK按钮

时间:2015-12-08 15:30:47

标签: ios objective-c mpmovieplayercontroller

我已经使用MPMoviePlayerController在我的网页视图中从实时网址播放视频 但是当我弹出视图控制器时,那时黑色屏幕出现在视图中,导航栏标题会发生变化。

- (void)viewDidLoad
{
    [super viewDidLoad];



    NSURL *movieURL = [NSURL URLWithString:self.url];
    self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    self.moviePlayer.contentURL = movieURL;

    if (self.moviePlayer)
    {
        [self.moviePlayer prepareToPlay];

        self.moviePlayer.view.frame = self.view.bounds;

        [self.view addSubview:self.moviePlayer.view];
        [self.moviePlayer.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];

        // save the movie player object
        [self.moviePlayer setFullscreen:YES];
        [self.moviePlayer setShouldAutoplay:YES];
        [self.moviePlayer setAllowsAirPlay:YES];

        // Play the movie!
        [self.moviePlayer play];

        [self initializeNavigationController];


    }


}

-(void)initializeNavigationController
{

    UIBarButtonItem *buttonBack = [[UIBarButtonItem alloc] backButtonWithtarget:self action:@selector(Back)];

    self.navigationItem.leftBarButtonItem = buttonBack;
}

-(void)Back
{

    [self.moviePlayer.view removeFromSuperview];
    [self stopLoadingVideoInView];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

直播视频画面 enter image description here

按下后退按钮 enter image description here

4 个答案:

答案 0 :(得分:0)

我想你只需删除 [self.view removeFromSuperview]; 并替换为 [self.movi​​ePlayer.view removeFromSuperview];

答案 1 :(得分:0)

如果您将youMovieController添加为父视图的子视图,请使用此方法将其删除。

[self.view removeFromSuperView] 

如果您是通过UINavigationController推送viewController,只需调用它返回。

[self.navigationCotroller popViewController:animated] 

如果您在ViewController中,请使用它来删除它。

[self dismissViewController] 

答案 2 :(得分:0)

我终于解决了它

在app delgate中我创建了一个方法来再次为vc分配内存

- (void)resetAppToFirstController
{
    UIViewController *obj = [[MainMenuViewController alloc] init];


    //Create Navigation Controller to Hold View Controller
    UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:obj];
   [self.window setRootViewController:navigationController];
}

以及我的后退按钮操作

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    appDelegate.resetAppToFirstController;

这解决了我的问题,它可能对MPMoviePlayer的某些人有帮助

答案 3 :(得分:0)

删除[self.view removeFromSuperview];并替换为[self.movi​​ePlayer.view removeFromSuperview];

var activeTemplate = await exec.DbContext.FormTemplates
.FirstOrDefaultAsync(x => x.Id == exec.Form.ActiveTemplateId); // slow

var activeTemplate = exec.DbContext.FormTemplates
.FirstOrDefault(x => x.Id == exec.Form.ActiveTemplateId); // fast