The AudioPlayer class is unique. He lives only for a short period of time. In an application using BackgroundAudioPlayer, the implementation of the AudioPlayer class will only be left alive to complete the task of changing the playback state. So, when the user starts to play something, an instance of your AudioPlayer class will be created to complete the task of starting playback. As soon as you call NotifyComplete () on OnUserAction or OnPlayStateChanged, the instance of your AudioPlayer leaves.
The background stream that AudioPlayer is associated with will still be active, and you may have other objects in that stream, but AudioPlayer will be terminated. The default AudioPlayer hints at this using the _classInitialized field. This is static because AudioPlayer will be created many times, but we only want to sign this event once.
I would suggest one of two things. First, you only need to get json's answer when you need to go to the next song. You will not call NotifyComplete () until the response returns. Here are a few pseudo codes:
override OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { GetJsonResponse(); } private void GetJsonResponce() {
The second is to have a class that does this in the background. This class will have a static property to get an instance that is live in the stream. Then your AudioPlayer will receive the information that it needs from this object.
public class Songs { static Songs _instance; public static Songs Instance { get { return _instance ?? new Songs(); } }
source share