Matt Gallagher AudioStreamer on iPhone - Failed to configure network read stream

I use the Matt Gallagher algorithm for streaming MP3s on iOS, but sometimes when you pause the application and after a while resume the song, a message appears: "Unable to configure reading of the network stream." I have analyzed the code, but I do not see how to get around this error. Can anyone handle this error?

Matt Gallagher AudioStreamer Code

+6
source share
1 answer

I experienced the same thing with this third-party application and could not find a solution for this, and then I tried using my own avplayer (not avaudioplayer), which gives you the ability to pass using the function :initWithURL . here is a link to the class, by the way: http://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVPlayer_Class/Reference/Reference.html

Also here is 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 if the player is ready for the game, you add an observer above, and then you can check it as:

 - (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"); } } 

Hope this helps.

+5
source

Source: https://habr.com/ru/post/902932/


All Articles