I have an app that's 98% finished and very recently I stumbled upon a newly introduced bug. The app plays mp3's from a server coming from a playlist ( just a JSON list of track URL's, not an m3u file ).
Everything is working as expected, except when a track finishes playing.
At that moment the next track is auto selected and the UI is updated.
But the track is never played.
Also: the playbackLikelyToKeepUp
key value observer is not triggered.
I can read the duration
, … of that selected ( not playing ) AVPlayerItem.
So it is a valid object.
Everything does work when I press "next" or select a row in my tableview.
The strangest part for me is that the code is exactly the same for the user event ( pressing "next" ) and the auto play functionality. Both set a currentTrackIndex
on my PlaylistManager, which I observe for changes. This triggers a playCurrentTrack
method.
Is it possible it has something to do with NSNotificationCenter
?
I use this to check if the current track has finished playing, like so:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:self.currentAudioPlayerItem];
playerItemDidReachEnd
looks like this:
- (void)playerItemDidReachEnd:(NSNotification *)notification {
// same action as pressing 'next' button in my audioplayer UI controls
// which is working, I can also see some UI updates ( correct title etc. … )
[self pressedNext];
}
I'm thinking something with threads maybe, blocking the events that are triggered when loading the mp3 from the url? I see the mp3 information is being loaded in my http traffic tool.
Thanks.