So I know AVPlayerItemDidPlayToEndTimeNotification
is sent when a movie 'has played to its end time'.
My question is how does the player know if an item reaches its end time? I was playing a live stream generated by a 3rd party generator. It keeps updating the M3U8 and creating new TS files, which live streaming should do. But at some point my player receives an AVPlayerItemDidPlayToEndTimeNotification
and thus invokes my exit methods and quit. The 3rd party stream generator is still running OK though. I can restart the player and watch the streams.
Since the playing item is a live stream, playerItem.duration
is not a readable duration number, which makes finding the End Time more like a black magic to me...
Really confused on how does the player thinks it's end. My guess is maybe the TS file was problematic and made the player think the whole playing is over? But if so, should the player change its status to say sth instead of silently finish playing?
P.S. I also tried different ways like make one ts missing from the m3u8 list, or stop generating new ones so that the player would play current m3u8 and play past the last ts, nothing made the AVPlayerItemDidPlayToEndTimeNotification
magic happen....
I registered the notification as following:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:self.playerItem];
So.. it turns out that the problem is from the 3rd party stream generator. It had sth ('IV', as in Initialiation Vector) wrong when streaming the TS contents, so at some point AVPlayer read some spot on a TS, then consider the movie is finished, and thus sending AVPlayerItemDidPlayToEndTimeNotification
.... Not really an Objective-C issue I guess.
But my question of in what condition does AVPlayer
send AVPlayerItemDidPlayToEndTimeNotification
is still unknown. If anyone knows any details about this, please feel free to update here. Thanks!
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