1

私はiPhoneプログラミングに不慣れです。以下のコードは録音されたサウンドを再生するためのものですが、デバイスでサウンドを再生しないことを誰かが教えてくれますか?このコードにどのような間違いがあるかを誰かが教えてくれますか?

if(soundID)
{
    AudioServicesDisposeSystemSoundID(soundID);
}

//Get a URL for the sound file
NSURL *filePath = [NSURL fileURLWithPath:audiopath isDirectory:NO];
NSLog(@"%@",filePath);
//Use audio sevices to create the sound
AudioServicesCreateSystemSoundID((__bridge  CFURLRef)filePath, &soundID);

//Use audio services to play the sound
AudioServicesPlaySystemSound(soundID);

上記のコードでは、オーディオパスは音声リコアパスです。実はデータベースパスにはこんな感じで保存されています

/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/C974262E-7658-45EE-8E8C-290B780E7C3E/Documents/2012-12-18 13:50:56 +0000.caf

この後、パスを取得している間、次のように表示されます。

file://localhost/Users/User/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/C974262E-7658-45EE-8E8C-290B780E7C3E/Documents/2012-12-18%2013:50:56%20+0000.caf

このコードの間違いは何ですか?教えてください。

4

2 に答える 2

1

`NSURL * musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@" your audio file name "ofType:@" wav "]];

AVAudioPlayer * click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];

[クリック再生];`

于 2012-12-18T15:11:36.453 に答える
0

名前が上の名前と一致しないiOSでエンコードされる追加のスペースがあります

a)2012-12-18 13:50:56 + 0000.caf
b)2012-12-18 13:50:56%20 + 0000.caf

于 2012-12-18T14:15:56.900 に答える