private void ProcessPlayerClosed()
        {
            // The session finished to close, we have to dispose all related object.
            currentMusic = null;

            mediaSessionCallback.Dispose();

            if (mediaSource != null) mediaSource.Shutdown();
            if (mediaSession != null) mediaSession.Shutdown();

            if (streamVolume != null) streamVolume.Dispose();
            if (mediaSource != null) mediaSource.Dispose();
            if (topology != null) topology.Dispose();
            if (mediaSession != null) mediaSession.Dispose();
            if (mediaInputByteStream != null) mediaInputByteStream.Dispose();

            topology = null;
            streamVolume = null;
            mediaSession = null;
            mediaSource = null;
            mediaInputByteStream = null;
            mediaSessionCallback = null;
            isMusicPlayerReady = false;
        }
        /// <summary>
        /// Load a new music into the media session. That is create a new session and a new topology and set the topology of the session.
        /// </summary>
        /// <param name="music"></param>
        private void LoadNewMusic(SoundMusic music)
        {
            if (currentMusic != null || mediaSession != null)
                throw new AudioSystemInternalException("State of the audio engine invalid at the entry of LoadNewMusic.");

            music.Stream.Position = 0;
            mediaInputByteStream = new ByteStream(music.Stream);
            topology = CreateTopology(mediaInputByteStream, out mediaSource);
            MediaFactory.CreateMediaSession(null, out mediaSession);
            mediaSessionCallback = new MediaSessionCallback(mediaSession, OnMediaSessionEvent);
            mediaSession.SetTopology(SessionSetTopologyFlags.None, topology);

            currentMusic = music;
        }