2012-02-23 6 views
0

iPhoneアプリ(ライブラジオアプリ)を作っています。バックグラウンドモードで再生中に電話が鳴る場合は、

私のアプリはバックグラウンドモードでサポートされています。

しかし、ラジオアプリがバックグラウンドモードで再生されているときに電話が鳴ると、私のアプリはエラーで停止します。

MP AVAudioSessionDelegateMediaPlayerOnly end interruption. Interruptor <Phone> category <completed> resumable <0>, _state = 6 
MP endInterruptionFromInterruptor :: resuming playback 

私は自分のコードを変更しましたが、無駄です。

私のコードを追加します。私の間違いを教えてください。ありがとう。

AppDelegate.h

@interface AppDelegate : UIResponder <UIApplicationDelegate, AVAudioSessionDelegate> 

@property (assign, nonatomic) UIBackgroundTaskIdentifier bgTask; 
... ... 

@end 

AppDelegate.m

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 
     bgTask = [application beginBackgroundTaskWithExpirationHandler:^{ 
     // Clean up any unfinished task business by marking where you. 
     // stopped or ending the task outright. 
     [application endBackgroundTask:bgTask]; 
     bgTask = UIBackgroundTaskInvalid; 
    }]; 

    // Start the long-running task and return immediately. 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 

     // Do the work associated with the task, preferably in chunks. 

     [application endBackgroundTask:bgTask]; 
     bgTask = UIBackgroundTaskInvalid; 
    }); 
} 

- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
    bgTask = [application beginBackgroundTaskWithExpirationHandler:^{   
     [application endBackgroundTask:bgTask]; 
     bgTask = UIBackgroundTaskInvalid; 
    }];  
} 

viewController.m

あなたがこれを追加する必要が
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil]; 
moviePlayer = [[MPMoviePlayerController alloc] init]; 
[moviePlayer setContentURL:... m3u8]; 
[moviePlayer play]; 

答えて

0


[[のUIApplication sharedApplication] beginReceivingRemoteControlEvents]。