我正在構建一個遊戲應用程序,我需要播放動畫視頻及其相應的聲音(根據情況可能會有所不同)。我已經準備好所有的視頻和聲音文件,但我無法同時播放它們。我正在使用MPMoviePlayer用於視頻和AVFoundation框架來播放音頻。無論如何都可以同時運行這兩者嗎?iPhone:同時播放音頻和視頻
對於視頻:
MPMoviePlayerViewController *videoController = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[cellDetails objectForKey:@"AVFile"]]] autorelease];
[self presentMoviePlayerViewControllerAnimated:videoController];
對於聲音:
// Instantiates the AVAudioPlayer object, initializing it with the sound
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error: nil];
self.appSoundPlayer = newPlayer;
[newPlayer release];
[appSoundPlayer prepareToPlay];
appSoundPlayer.numberOfLoops = -1;
[appSoundPlayer setVolume: self.soundLevel];
[appSoundPlayer setDelegate: self];
[appSoundPlayer play];
感謝。
取決於您如何使用AVFoundation。想發佈一些代碼? –
請參閱編輯的問題。謝謝! – applefreak