gpt4 book ai didi

ios - ios 8从后台进入前台时如何播放MPMoviePlayerController?

转载 作者:行者123 更新时间:2023-11-28 21:53:08 26 4
gpt4 key购买 nike

我的 MPMoviePlayerViewController 有问题,当应用程序进入后台然后我再次启动它时,电影变成了黑色!我有在我的菜单背景中播放的电影,这是我的代码:

这是我的 AppDelegate.m

  • (void)applicationWillResignActive:(UIApplication *)application

{

[[NSNotificationCenter defaultCenter] postNotificationName:@"WillResignActive" object:nil];

  • (void)applicationDidEnterBackground:(UIApplication *)application

{

[[NSNotificationCenter defaultCenter] postNotificationName:@"WillResignActive" object:nil];

  • (void)applicationWillEnterForeground:(UIApplication *)application

{

[[NSNotificationCenter defaultCenter] postNotificationName:@"WillEnterForeGround" object:nil];

  • (void)applicationDidBecomeActive:(UIApplication *)application

{

[[NSNotificationCenter defaultCenter] postNotificationName:@"DidBecomeActive" object:nil];

ViewController.m

  • (无效)viewDidLoad

{

[super viewDidLoad];
// Do any additional setup after loading the view.

NSURL *url = [NSURL URLWithString:@"http://1080Digital.stream/playlist.m3u8"];

mp = [[MPMoviePlayerViewController alloc]initWithContentURL:url];

[self presentMoviePlayerViewControllerAnimated:mp];

mp.view.frame = self.view.bounds; //Set the size

self.view.backgroundColor=[UIColor clearColor];

mp.moviePlayer.controlStyle =MPMovieControlStyleNone;

mp.moviePlayer.scalingMode = MPMovieScalingModeFill;

mp.moviePlayer.repeatMode = MPMovieRepeatModeOne;

mp.moviePlayer.view.userInteractionEnabled = YES;

mp.moviePlayer.movieSourceType=MPMovieSourceTypeStreaming;

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(AppDidBecomeActive) name:@"DidBecomeActive" object:nil];

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(EnteredBackground) name:@"WillResignActive" object:nil];

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(EnteredForeground) name:@"WillEnterForeGround" object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackStateChange)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:[mp moviePlayer]];

[mp.moviePlayer prepareToPlay];

[mp.moviePlayer prepareToPlay];

[mp.moviePlayer play];


[self.view addSubview:mp.view];

-(void)moviePlayBackStateChange

{

[[mp moviePlayer] play];

-(void)AppDidBecomeActive

{

if(mp.moviePlayer.playbackState == MPMoviePlaybackStateInterrupted || mp.moviePlayer.playbackState == MPMoviePlaybackStateStopped || mp.moviePlayer.playbackState == MPMoviePlaybackStatePaused)

{

[mp.moviePlayer play];

}

-(void)EnteredBackground

{

[[mp moviePlayer] pause];

[mp.view removeFromSuperview];

-(void)进入前景{

[self.view addSubview:mp.view];

[[mp moviePlayer] play];

最佳答案

只有你需要实现

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(EnteredForeground) name:@"WillEnterForeGround" object:nil];

and in

(void)applicationWillEnterForeground:(UIApplication *)application

{

[[NSNotificationCenter defaultCenter] postNotificationName:@"WillEnterForeGround" object:nil];

}

关于ios - ios 8从后台进入前台时如何播放MPMoviePlayerController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27542565/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com