我正在构建一个游戏应用程序,我需要播放动画视频及其相应的声音(根据情况可能会有所不同)。我已经准备好所有的视频和声音文件,但我无法同时播放它们。我正在使用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