我正在使用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中的播放器?
答案 0 :(得分:1)
尝试导入MPMoviePlayerController所在的类。在AppDelegate.h“import "YourClassNameWithThePlayer.h"
”中使用此代码。
也许这可以帮助。我也是新人,我希望你考虑一下。