AudioStreamer icon indicating copy to clipboard operation
AudioStreamer copied to clipboard

How to download the song when playing?

Open shingo1017 opened this issue 13 years ago • 5 comments

I wanna cache the song to file when playing, please who knows?

shingo1017 avatar Oct 08 '11 02:10 shingo1017

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 :)

tomwilsn avatar Oct 14 '11 08:10 tomwilsn

it's helpful. I will try it.

foreveryh avatar May 30 '12 09:05 foreveryh

@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 avatar Dec 18 '12 20:12 emile818

@emile818 I just used C functions like fopen, fwrite, and fclose

azone avatar Dec 20 '12 07:12 azone

@emile818 can you share the code to write audio into local directory?

bbalachandhar avatar Jun 02 '15 11:06 bbalachandhar