AudioStreamer
AudioStreamer copied to clipboard
How to download the song when playing?
I wanna cache the song to file when playing, please who knows?
in the - (void)handleReadFromStream:(CFReadStreamRef)aStream eventType:(CFStreamEventType)eventType callback just write the bytes to disk...
Of course then you will have the issue of this Streamer not supporting local file playback. I've managed to get it to do that, and it wasn't very hard - Basically replace the CFReadStream stuff with an NSURLConnection instead (which works fine with file URL's).
That said, AVQueuePlayer does a lot of what this does now, so if you don't mind only supporting iOS 4.0+ (which isn't really a big deal) You might be better off using that instead, unless you need the flexibility of this streamers low-level approach. Which I guess you might do if you wish to save the files as you play them, or any other number of reasons :)
it's helpful. I will try it.
@Kabal @foreveryh how did you write the bytes to the disk? thx
// USE this condition or something to validate
NSString * escapedValue = [NSString stringWithFormat:@"%@", XXXXXX];
NSData * mp3Ddata = [NSData dataWithBytes:bytes length:length];
NSFileHandle* outputFile = [NSFileHandle fileHandleForWritingAtPath:escapedValue];
[outputFile seekToEndOfFile];
[outputFile writeData:mp3Ddata];
[outputFile closeFile];
I tried this but didn't support all the kind of streams url for some reason
@emile818 I just used C functions like fopen, fwrite, and fclose
@emile818 can you share the code to write audio into local directory?