4

Hi I'm trying to play two different files at the same time.

I tried to create several players using AVFoundation and MediaPlayer, but it doesn't work well. What's the best way to play audio file and video at the same time?

The reason I'm taking separate files is to save space, because the app will be localized, having only 26 audio files for each language instead of having 26 videos saves space. That's important because apple doesn't allow the download of app size above 100 MB.

4

1 に答える 1

1

AVAudioPlayerと組み合わせて使用​​することをお勧めしますMPMoviePlayerController

の場合はAVAudioPlayer、アンビエント セッションに設定します。これにより、別のメディア ソースを同時に再生できます。以下にいくつかのコードを投稿しました。これは、私が行ったサイド プロジェクトから取得したもので、私のGitHubにあります。

AVAudioPlayer audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];

NSURL *movieURL = [NSURL fileURLWithPath:
                   [[NSBundle mainBundle] pathForResource:@"movie"
                                                   ofType:@"mp4"]];

MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[[moviePlayer view] setFrame:someFrame];
[self.view addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
[moviePlayer setRepeatMode:MPMovieRepeatModeOne];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[moviePlayer play];

これを変更可能にしたい場合は、別のオーディオ URL を同じオーディオ プレーヤーにロードするだけでよいでしょう。

于 2013-11-13T12:15:42.927 に答える