如何从appdelegate中的applicationwillresignactive调用mpmovieplayer?

时间:2012-04-01 05:26:01

标签: audio-streaming mpmovieplayer audiosession

我正在使用mpmovieplayer播放音频流。我在处理入侵时遇到了麻烦,例如收到电话时。我的播放器在viewcontroller中声明,我相信我需要在applicationdidresignactive的{​​{1}}权限中执行某些操作?如果我的appdelegate不了解我的appdelegate,我该怎么做?我是iPhone开发的新手,所以我在学习的同时享受它:)

以下是我在moviePlayer

中所做的事情
viewcontroller

并在-(IBAction)play1MButton:(id)sender{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerStatus:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil]; NSString *url = @"http://22.22.22.22:8000/listen.pls"; [self.activityIndicator startAnimating]; moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]]; [moviePlayer prepareToPlay]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil]; } -(void) moviePlayerStatus:(NSNotification*)notification { //MPMoviePlayerController *moviePlayer = notification.object; MPMoviePlaybackState playbackState = moviePlayer.playbackState; if(playbackState == MPMoviePlaybackStateStopped) { NSLog(@"MPMoviePlaybackStateStopped"); } else if(playbackState == MPMoviePlaybackStatePlaying) { NSLog(@"MPMoviePlaybackStatePlaying"); } else if(playbackState == MPMoviePlaybackStatePaused) { NSLog(@"MPMoviePlaybackStatePaused"); } else if(playbackState == MPMoviePlaybackStateInterrupted) { NSLog(@"MPMoviePlaybackStateInterrupted"); } else if(playbackState == MPMoviePlaybackStateSeekingForward) { NSLog(@"MPMoviePlaybackStateSeekingForward"); } else if(playbackState == MPMoviePlaybackStateSeekingBackward) { NSLog(@"MPMoviePlaybackStateSeekingBackward"); } } - (void) moviePlayerLoadStateChanged:(NSNotification*)notification { if ([moviePlayer loadState] != MPMovieLoadStateUnknown) { [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:moviePlayer]; [moviePlayer play]; [self.activityIndicator stopAnimating]; [moviePlayer setFullscreen:NO animated:NO]; } }

appdelegate

我可以捕捉错误,但我如何使用appdelegate中的播放器?

1 个答案:

答案 0 :(得分:1)

尝试导入MPMoviePlayerController所在的类。在AppDelegate.h“import "YourClassNameWithThePlayer.h"”中使用此代码。 也许这可以帮助。我也是新人,我希望你考虑一下。