Search code examples
objective-cqtkit

playing music by url


I want to play the music from internet by url. I create a simply project that has one button with the following code:

NSURL *url = [[NSURL alloc] initWithString:@"http://someURL.mp3"];
NSError **err;
QTMovie *movie = [[QTMovie alloc] initWithURL:url error:err];
[movie play];

It works but with some delay (I think because it waits while file has been fully downloaded).
So what I need to do that the music starts to play immediately (when, for example, 10% of file has been downloaded)?


Solution

  • Use -[QTMovie autoplay] to automatically play the music once enough data has been downloaded.

    In your case:

    NSURL *url = [[NSURL alloc] initWithString:@"http://someURL.mp3"];
    NSError **err;
    QTMovie *movie = [[QTMovie alloc] initWithURL:url error:err];
    [movie autoplay];
    

    From the QTMovie class reference:

    The autoplay method configures a QTMovie object to begin playing as soon as enough data is available that the playback can continue uninterrupted to the end of the movie.