Trying to play sound through iPhone Simulator

I am trying to play a sound file from an iPhone program.

Here is the code:

NSString *path = [[NSBundle mainBundle] pathForResource:@"play" ofType:@"caf"];
NSFileHandle *bodyf = [NSFileHandle fileHandleForReadingAtPath:path];
NSData *body = [bodyf availableData];
NSLog( @"length of play.caf %d",[body length] );
NSURL *url = [NSURL fileURLWithPath:path isDirectory:NO];
NSLog( [url description] );
NSLog( @"%d", AudioServicesCreateSystemSoundID((CFURLRef)url, &soundID) );

The first NSLog should check that I have access to the file (I did), the second NSLog should show the URL of the file, and the third NSLog will return -1500 "An unspecified error has occurred".

For the second NSLog, I get the following output:

file: // localhost / Users / alan / Library / Application 敲 慬 楴 敶 瑓 楲 杮 up / iPhone 蒠 ꁻ ތ Ā ⾅ 獕 祲 䄯 灰 楬 楴 湯 匠 湯 湯 湯 湯 湯 湯 湯 湯 湯 ⁥ 楓 畭 慬 潴 潴⽲ 獕 牥 䄯 灰 楬 慣 楴 湯 ⽳ ⴸ 㕅 㡂 㤱 㤱 䌭 䐳 ⴸ 䐴 䙃 㠭 ㍃ⴷ 䍁 ㈶ ㈶ 㠵 䙁 㤴 ㈰ 䰯 捯 瑡 䵥 ⹥ 灡 ⽰ 汰 祡 挮 晡 imulator / Custom / Applications / BFE5B819 -C3D8-4DC -8C37-AC6258AF4902 / LocateMe.app / play.caf

This is either due to my misunderstanding of the "description" method, or it contributes to the problem.

Any idea what is going wrong?

+2
5

.

, .

, .caf , .

.

.wav, 60 , .

.wav 5 , .

.aiff 5 .

, , AudioServicesCreateSystemSoundID

+1

NSLog ; [URL description] NSLog. , , URL- %, .

NSLog(@"%@", URL);

-description ; NSLog , %@ "", "NSString", , .

+3

, , iPhone (systemSound) 5 . , , systemSound.

, , , . , . Apple. , iPhone SDK 3.0.

+3

, . , NSLog URL, , , EXC_BAD_ACCESS . URL- , URL- , EXC_BAD_ACCESS. , , . - , . , Id .

0
source

Use the "AVAudioPlayer" Class to Play .caf Files

0
source

All Articles