我mpmovieplayer
用来播放音频流。我在处理中断时遇到问题,例如接到电话时。我的球员被宣布加入,我相信我需要在我的权利范围viewcontroller
内做点什么?如果我不知道我的,我该怎么做?我是 iPhone 开发的新手,所以我边走边学,享受它 :)applicationdidresignactive
appdelegate
appdelegate
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
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
if (setCategoryError) {
}
NSError *activationError = nil;
[audioSession setActive:YES error:&activationError];
if (activationError) {
}
我可以捕捉到错误,但是如何使用来自 appdelegate 的播放器?