views:

2001

answers:

3

I'd like to play sound file which loaded from internet, so I tried to start from iPhone SDK SpeakHere sample. I recorded the sound, then saved and uploaded to the internet, I could download that file and play without problem from sound tools. But when I tried to play that URL from SpeakHere, I am getting error Program received signal: “EXC_BAD_ACCESS”.

After trace around, I found that the in -[AudioPlayer calculateSizesFor:], it set bufferByteSize to a huge number 806128768, which caused buffer allocation failed.

And that because in

AudioFileGetProperty(audioFileID, kAudioFilePropertyPacketSizeUpperBound, &propertySize, &maxPacketSize);

The maxPacketSize returned is 806128768.

I am wondering how to make AudioFileGetProperty work.

My sound file is here http://chineseresume.com/localbiz/uploads/myfilename_7_Recording.caf, you could right mouse click and download from http://chineseresume.com/test.html

I am using this way to set the URL in the -[AudioViewController playOrStop] method:

// AudioPlayer *thePlayer = [[AudioPlayer alloc] initWithURL: self.soundFileURL];
AudioPlayer *thePlayer = [[AudioPlayer alloc] initWithURL:
    [NSURL URLWithString: @"http://chineseresume.com/localbiz/uploads/myfilename_7_Recording.caf"]];

Any suggestion is highly welcome. Thanks!

A: 

I figured out a workaround. That is copy the content from internet to a local file, then play sound from that local file. And appears solve the problem.

Not perfect, but just works. If anyone has real solution, please let me know. Thanks.

Here is the code to copy from internet to local file. -(CFURLRef)saveURL:(NSString *)urlString { NSURL url = (NSURL)[[NSURL alloc] initWithString:urlString]; NSData *data = [[NSData alloc] initWithContentsOfURL:url]; NSArray *filePaths = NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory, NSUserDomainMask, YES );

NSString *recordingDirectory = [filePaths objectAtIndex: 0];

CFStringRef fileString = (CFStringRef) [NSString stringWithFormat: @"%@/BufferFile.caf", recordingDirectory];
NSLog(@"fileString = %@" , fileString);
// create the file URL that identifies the file that the recording audio queue object records into
CFURLRef fileURL = CFURLCreateWithFileSystemPath (               NULL,   fileString,              kCFURLPOSIXPathStyle,            false);
SInt32 err = 0;

CFURLWriteDataAndPropertiesToResource (

fileURL, (CFDataRef)data, nil, &err); return fileURL; }

BlueDolphin
+1  A: 

I think the main problem is that the code you are using deals with AudioFile objects (local audio files on disk) but when you load audio from the network you want to use AudioFileStream, which has its own set of API calls to use such as AudioFileStreamOpen, AudioFileStreamParseBytes, etc.

Marc Novakowski
+3  A: 

Yes, you need to use Audio File Stream Services to play directly from the internet.

I found the "AudioFileStreamExample" example useful, which should be installed in

/Developer/Examples/CoreAudio/Services/AudioFileStreamExample/

Also, Matt Gallagher has an article called "Streaming and playing an MP3 stream" that includes iPhone example code. I haven't looked at it carefully, but it seems like it may be helpful to you.

amrox