private void OnPlayerEvent (PlayerEventArgs args)
{
if (args.Event == PlayerEvent.EndOfStream) {
// If EoS is for the last track in the play queue
if (this == ServiceManager.PlaybackController.Source &&
TrackModel.IndexOf (current_track) == Count - 1) {
SetCurrentTrack (null);
UpdatePlayQueue ();
if (was_playing) {
ServiceManager.PlaybackController.PriorTrack = prior_playback_track;
} else {
// Stop playback; nothing was playing before the play queue, so it doesn't
// make sense to continue playback.
ServiceManager.PlaybackController.StopWhenFinished = true;
}
}
if (ServiceManager.PlaybackController.StopWhenFinished) {
if (current_track != null && this == ServiceManager.PlaybackController.Source) {
int index = TrackModel.IndexOf (current_track) + 1;
SetCurrentTrack (index < Count ? TrackModel[index] as DatabaseTrackInfo : null);
}
}
} else if (args.Event == PlayerEvent.StartOfStream) {
if (TrackModel.IndexOf (ServiceManager.PlayerEngine.CurrentTrack) != -1) {
SetCurrentTrack (ServiceManager.PlayerEngine.CurrentTrack as DatabaseTrackInfo);
SetAsPlaybackSourceUnlessPlaying ();
UpdatePlayQueue ();
} else {
prior_playback_track = ServiceManager.PlayerEngine.CurrentTrack;
}
}
}