複数の.m4aファイルを連続して再生するにはどうすればよいですか?
現在、私の関数はAudioServicesPlaySystemSoundなどを使用して再生を開始し、AudioServicesAddSystemSoundCompletionを使用してコールバックを選択してから戻ります。サウンドが完了すると、コールバックによってソフトウェアが続行されます。
これは、背中合わせの音があるときはいつでもたくさんのコーディングです。
私のソフトウェアは.m4aの再生を開始でき、コールバックがフラグを設定するのを待って、ソフトウェアが完了するのを待つことができますか?pthreadソフトウェアを使用して、マルチタスク一時停止で待機ループを実行できますか?
これがこれまでの私のコードです...
//サウンドファイルを再生した後、game_stateを復元してゲームを続行します。int game_state_after_sound; void play_sound_file_done(SystemSoundID ssID、voidcalling_class ){printf( "\ nplay_sound_file_done。"); //サウンドが完成したので、game_stateを復元し、中断したところからmanage_gameを続行します。game_state= game_state_after_sound; [(GeController)calling_class manage_game]; }
// Plays sound_file_m4a and returns after playing has completed.
-(void) play_sound_file: (NSString *) sound_file_m4a
{
printf("\n play_sound_file '%s' ", [sound_file_m4a UTF8String] );
NSString *soundPath = [[NSBundle mainBundle] pathForResource:sound_file_m4a ofType:@"m4a"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);
AudioServicesAddSystemSoundCompletion ( soundID, NULL, NULL, play_sound_file_done, (void*)self );
game_state_after_sound = game_state;
game_state = DELAY_WHILE_PLAYING_SOUND;
}
**********************************AVPlayerの進行中の作業中...
しかし、これでは音が出ません。
#import <AVFoundation/AVFfoundation.h>
-(void) play_queued_sounds: (NSString *) sound_file_m4a
{
printf("\n queue_sound_file: '%s' ", [sound_file_m4a UTF8String] );
AVPlayerItem *sound_file = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:sound_file_m4a ofType:@"m4a"]]];
AVQueuePlayer *player = [AVQueuePlayer queuePlayerWithItems:[NSArray arrayWithObjects:sound_file, nil]];
[player play];
return;
}