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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With