开发者

CFReadStreamRef and size of bytes available

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 th开发者_Go百科e 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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜