2012-01-05 254 views
0

我需要在iPhone中從網站播放音頻文件(.wav)。我正在使用MPMoviePlayerViewController來播放音頻播放器。有時候應用程序正在崩潰。音頻播放器在iPhone中播放遠程音頻文件?

我的代碼:

NSURL * videoURL = [NSURL URLWithString:appDelegate.selectedQuestion.GraphicsUrl];

 videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL]; 
     [[MPMusicPlayerController applicationMusicPlayer] setVolume:1.0]; 
     MPMoviePlayerController *moviePlayer = [videoPlayer moviePlayer]; 

     [moviePlayer setScalingMode:MPMovieScalingModeAspectFit]; 
     [videoPlayer.view setFrame: videoView.bounds]; 
     [moviePlayer.view setFrame:videoPlayer.view.bounds]; 
     [moviePlayer.backgroundView setFrame:videoPlayer.view.bounds]; 
     [videoView addSubview:videoPlayer.view]; 

     [moviePlayer setShouldAutoplay:NO]; 
     [moviePlayer setFullscreen:YES]; 
     [moviePlayer setFullscreen:NO]; 
     [moviePlayer setCurrentPlaybackTime:(NSTimeInterval)1]; 
     [moviePlayer setInitialPlaybackTime:(NSTimeInterval)1]; 
     [moviePlayer setControlStyle:MPMovieControlStyleDefault]; 
     [moviePlayer setCurrentPlaybackTime:(NSTimeInterval)-1]; 

例外:

mediaserverd (sandbox) 
Dec 29 23:48:43 unknown mediaserverd[3132] <Error>: 23:48:43.312834 com.apple.AVConference: /SourceCache/GameKitServices/GameKitServices-344.3/AVConference.subproj/Sources/AVConferenceServer.m:1867: AVConferenceServerStart 
Dec 29 23:48:43 unknown SMILE[2823] <Warning>: _serverConnectionDiedNotification. Info -- notification=Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo=0x7f7c660 {NSLocalizedRecoverySuggestion=Try again later., NSLocalizedDescription=Cannot Complete Action}, AVPlayer = <MPQueuePlayer: 0xac97410>, currentTime = 8.78 
Dec 29 23:48:43 unknown SMILE[2823] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An AVPlayerItem cannot be associated with more than one instance of AVPlayer' 
+0

我不知道你爲什麼使用兩個實例(videoPlayer,moviePlayer)?如果您看到崩潰,則顯示:'一個AVPlayerItem不能與多個AVPlayer實例關聯'。另外,我不知道方法 - [MPMoviePlayerController moviePlayer]。要刪除音頻播放,您可以參考幾個問題。 – Ravin 2012-01-05 11:31:51

回答

0

我以前遇到死機一樣,我通過刪除所有的MPMoviePlayerController通知固定它也釋放出的MPMoviePlayerController本身(注意,這兩個應該做的,否則崩潰仍會發生!)一旦播放狀態轉到MPMoviePlaybackStateStopped。我仍然不知道確切的原因,只有我知道的是,如果玩家不斷進入MPMoviePlaybackStateStopped狀態,它會崩潰,所以我只是阻止它停止兩次。

希望這會有所幫助。