ユーザーが iPad で実行されているアプリケーションのボタンをクリックしたときに、システム サウンドを再生する必要があります。iOSで実装するには?
3270 次
3 に答える
11
短い音 (30 秒未満) を再生する場合は、次のように簡単に実行できます。
注: AudioToolbox フレームワークを追加してインポートする必要があります ( #import <AudioToolbox/AudioToolbox.h>
)
SystemSoundID mySSID;
NSString *path = [[NSBundle mainBundle] pathForResource:@"beep" ofType:@"wav"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: path], &mySSID);
AudioServicesPlaySystemSound(mySSID);
また、ファイルは次のようになる可能性があることに注意してください。
- 継続時間は 30 秒以内
- リニア PCM または IMA4 (IMA/ADPCM) 形式
- .caf、.aif、または .wav ファイルにパッケージ化
于 2012-05-24T14:04:37.737 に答える
3
AVAudioPlayer を使用する必要があります。
AVAudioPlayer を使用してサウンドを再生するための優れたチュートリアルがここにあります。その使用の非常に簡単な例:
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audiofile.mp3",dataPath];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (audioPlayer == nil)
NSLog([error description]);
else
[audioPlayer play];
于 2012-05-24T13:50:13.290 に答える
0
NSString *path = [[NSBundle mainBundle] pathForResource:@"gorilla 2" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
于 2012-10-08T06:05:35.883 に答える