开发者

Progressive download using Matt Gallagher's audio streamer

I'm a completely n00b when talking about audio. I'm using Matt Gallagher's audio streamer on my radio app. How may I use progressive download? Also, ExtAudio开发者_Python百科File is a good idea too :)

Edit:

Used this:

length = CFReadStreamRead(stream, bytes, kAQDefaultBufSize);            
if(!data)
    data =[[NSMutableData alloc] initWithLength:0];             
[data appendData:[NSData dataWithBytes:bytes length:kAQDefaultBufSize]];

Now I can save the audio data using writeToFile:atomically: NSData method, but the audio won't play. Also, if I try to load it on a AVAudioPlayer, I get an error.


I'm trying to do something similar. I ended up doing it like this:

        length = CFReadStreamRead(stream, bytes, kAQDefaultBufSize); 

        // Save data
        if (saveLocation){
            NSFileHandle *mp3 = [NSFileHandle fileHandleForWritingAtPath:saveLocation];

            [mp3 seekToEndOfFile];
            [mp3 writeData:[NSData dataWithBytes:bytes length:length]];

            [mp3 closeFile];
        }

Some problems to be aware of. You should make sure that the file at saveLocation exists. I made a new initializer with the mp3 url and saveLocation path, and put the check there. Also, be aware that if the user performs a seek in the mp3 this will not realize that. Basically, it will record exactly what gets played back. It is not smart enough to realize that the playback position moved. However, if you just start the stream, and allow it to finish the whole mp3 (assuming that it has an end) it should save just fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜