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