Reputation: 15894
In my app, i'm using MPMoviePlayerController to play a streaming video from my server. I'm hiding the controls and have my own button to indicate whether the player is playing, paused or stopped. I want to enable/disable the buttons depending on the state of streaming.
I'm using following code to initiate the player:
self.avPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:audioURL]];
[self.avPlayer.moviePlayer setShouldAutoplay:YES];
[self.avPlayer.moviePlayer prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlayStateChanged:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
When the play starts, i'm getting the notification. But if due to some reason, wifi is slow or not available, player might be streaming and I'm not getting any notification. Why am I not getting notification when the video is streaming?
Also when the video is streaming in middle, the player stops and throws "finished" notification. How to prevent it from stopping during streaming.....
Upvotes: 2
Views: 4414
Reputation: 1913
Before anything else, I think you should specify the movieSourceType property:
self.avPlayer.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
Now, about the notifications,
playbackState
property before and after to see why the notification was called, when and if it gets called.MPMoviePlayerLoadStateDidChangeNotification
and check the loadState property (like the notification for PlaybackStateChanged there is no userinfo dictionary so you have to read it through the loadState
property).MPMoviePlayerPlaybackDidFinishNotification
getting thrown during streaming I'm guessing there was some error, since other options would be the movie reached the end or the user stopped the movie himself. Again, you can check to see why the notification was called by reading the MPMovieFinishReason
constant that gets passed as a key in the userinfo dictionary parameter of the notification.Upvotes: 4