私はmpmovieplayer
を使用してオーディオストリームを再生しています。私は、通話が受信されたときのような中断の処理に問題があります。私のプレーヤーはviewcontroller
で宣言されており、私はappdelegate
の中でapplicationdidresignactive
で何かする必要があると私は信じていますか? appdelegate
が私のmoviePlayer
を認識していない場合はどうすればよいですか?私は私が行くように学習し、それを楽しんでいますので、私はiPhoneの開発に新たなんだ:)ここppdelegateのapplicationwillresignactiveからmpmovieplayerを呼び出すにはどうすればよいですか?
は私が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からプレーヤーを使用するのですか?
誰でもいいですか?私はまだそれを把握できません! :( – ss30