How to make QTMovie play a file with a forced (MP3) type URL?

I use QTKit to gradually download and play MP3s from a URL. According to this documentation , this is the code I should use for this:

NSURL *mp3URL = [NSURL URLWithString:@"http://foo.com/bar.mp3"];

NSError *error = nil;
QTMovie *sound = [[QTMovie alloc] initWithURL:mp3URL error:&error];
[sound play];

This works and does exactly what I want - the MP3 URL lazily loads and starts playing right away. However, if the URL does not have the extension ".mp3", it does not work:

NSURL *mp3URL = [NSURL URLWithString:@"http://foo.com/bar"];

NSError *error = nil;
QTMovie *sound = [[QTMovie alloc] initWithURL:mp3URL error:&error];
[sound play];

An error is not indicated, an exception does not occur; the duration of the sound is simply zero, and nothing is reproduced.

The only way I came across is to force the type to load data manually and use QTDataReference:

NSURL *mp3URL = [NSURL URLWithString:@"http://foo.com/bar"];
NSData *mp3Data = [NSData dataWithContentsOfURL:mp3URL];

QTDataReference *dataReference = 
    [QTDataReference dataReferenceWithReferenceToData:mp3Data
                                                 name:@"bar.mp3"
                                             MIMEType:nil];
NSError *error = nil;
QTMovie *sound = [[QTMovie alloc] initWithDataReference:dataReference error:&error];
[sound play];

MP3 , , . ?

.

, , ; Content-Type HTTP-. , , - . - , ?

2

-? , Google ...

+5
4

. ( ):
, - Cocoa, NSURL "".

Cocoa http-:

- ( QTKit AudioToolbox).
, , mp3 AudioToolbox.
.: http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html

. AudioToolbox , QTKit, . iOS, Mac OS, .

Update:
?

+ (id)movieWithAttributes:(NSDictionary *)attributes error:(NSError **)errorPtr

URL- QTMovieURLAttribute , , , . QTMovie, : http://vidnik.googlecode.com/svn-history/r63/trunk/Source/Categories/QTMovie+Async.m

0

, weichsel's , :

- Content-Type, . QTKit.framework Objective-C , -[NSHTTPURLResponse allHeaderFields] . QTKit.framework ( ) Core Foundation ( ) . C-, C.

, , . interposition Apple, , , , .

, - :

typedef struct interpose_s {
    void *new_func;
    void *orig_func;
} interpose_t;

CFStringRef myCFHTTPMessageCopyHeaderFieldValue (
                                                 CFHTTPMessageRef message,
                                                 CFStringRef headerField
                                                 );

static const interpose_t interposers[] __attribute__ ((section("__DATA, __interpose"))) = {
    { (void *)myCFHTTPMessageCopyHeaderFieldValue, (void *)CFHTTPMessageCopyHeaderFieldValue }
};

CFStringRef myCFHTTPMessageCopyHeaderFieldValue (
                                                 CFHTTPMessageRef message,
                                                 CFStringRef headerField
                                                 ) {
    if (CFStringCompare(headerField, CFSTR("Content-Type"), 0) == kCFCompareEqualTo) {
        return CFSTR("audio/x-mpeg");
    } else {
        return CFHTTPMessageCopyHeaderFieldValue(message, headerField);
    }
}

, , , Content-Type, , HTTP- .

0

Try replacing http://with icy://.

0
source

Just create such an instance ...

QTMovie *aPlayer  = [QTMovie movieWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                 fileUrl, QTMovieURLAttribute,
                                                 [NSNumber numberWithBool:YES], QTMovieOpenForPlaybackAttribute,
                                                 /*[NSNumber numberWithBool:YES], QTMovieOpenAsyncOKAttribute,*/
                                                 nil] error:error];
0
source

All Articles