Tutorial :CFReadStreamRef and size of bytes available



Question:

hai all,

I'm trying to implement a Streaming music Player using iphone sdk, based on the sample code by Matt Gallagher ( http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html)

now i would like to know how can i get the number of bytes available in the CFReadStreamRef .

After a long search i got the code to find the total size of the file

float audioFileSize = 0.0;
CFHTTPMessageRef myResponse = (CFHTTPMessageRef)CFReadStreamCopyProperty(stream, kCFStreamPropertyHTTPResponseHeader);
audioFileSize = [(NSString*)CFHTTPMessageCopyHeaderFieldValue(myResponse, (CFStringRef)@"Content-Length") floatValue];
CFRelease(myResponse);

I hope there will be some similar code to find the size of bytes available.

and also like to know how we can get duration of the music file in the stream and how long its played

thanks in advance


Solution:1

Content-Length is the number of bytes (octets) in the file. It's not a number of seconds, if that's what you were expecting.

As such, it will never be fractional, so you should use unsignedIntegerValue instead of floatValue.

Also, don't forget to release the two objects (at least) that you have Copied. See the Memory Management Programming Guide for Core Foundation.

As for audio-specific information, such as the number of seconds, you'll have to pass some data to Core Audio before you can find that out. CFReadStreams are generic byte-stream-reading objects; they don't know anything about audio or images or text or any other specific kind of data.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »