Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matt Gallagher's AudioStreamer in iPhone - unable to configure network read stream

I am using the Matt Gallagher's algorithm to perform mp3 streaming in iOS but sometimes when you pause the application and, after some time, resume the song a message pop up: "Unable to configure network stream read". I have analyzed the code, but I do not see how to get around this error. Has anyone managed to cope better with this error?

Matt Gallagher's AudioStreamer code

like image 660
flopes Avatar asked Dec 02 '11 13:12

flopes


1 Answers

I have experienced the same thing with this 3rd party app and could not find a solution for that and then I have tried apple's native avplayer (not avaudioplayer) which gives you the ability to stream with the function :initWithURL . here's the class reference, by the way : http://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVPlayer_Class/Reference/Reference.html

in addition here's my code for playing music :

NSURL *url = [[NSURL alloc] initWithString:sourceURL];
            theItem = [AVPlayerItem playerItemWithURL:url];
            theItem addObserver:self forKeyPath:@"status" options:0 context:nil];
            theAudio = [AVPlayer playerWithPlayerItem:mainDelegate.theItem];

to catch whether the player is readyto play you add the observer above and then you can check it like :

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
                        change:(NSDictionary *)change context:(void *)context {
    if (object == theItem && [keyPath isEqualToString:@"status"]) {
        if(theItem.status == AVPlayerStatusReadyToPlay)    
        {
            [theAudio play];
            [theItem removeObserver:self forKeyPath:@"status"];
        }
        else if(theItem.status == AVPlayerStatusFailed) {
            NSLog(@"%@" , mainDelegate.theItem.error.description);
        }
        else if(theItem.status == AVPlayerStatusUnknown)
            NSLog(@"unknown");
    }
}

I hope this helps.

like image 187
iremk Avatar answered Oct 06 '22 00:10

iremk