Exemplo n.º 1
0
        public void ReceiveNotification(string sourceFileUrl, NotificationType type)
        {
            // musicbee api stuff
            string artist        = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist);
            string trackTitle    = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.TrackTitle);
            string duration      = mbApiInterface.NowPlaying_GetFileProperty(FilePropertyType.Duration);
            bool   getSongLength = mbApiInterface.Player_GetShowTimeRemaining();
            string songLength    = getSongLength.ToString();
            int    position      = mbApiInterface.Player_GetPosition();

            // create new variables so we can modify them for certain situations
            string songName   = trackTitle;
            string songArtist = artist;

            // check if there is no artist so we can replace it with Unknown
            if (string.IsNullOrEmpty(artist))
            {
                songName   = trackTitle;
                songArtist = "Unknown";
            }

            // perform some action depending on the notification type
            switch (type)
            {
            case NotificationType.PluginStartup:
            // perform startup initialization
            case NotificationType.PlayStateChanged:
                switch (mbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                    UpdatePlayedPresence(songName, songArtist, duration, position / 1000);
                    break;

                case PlayState.Paused:
                    UpdatePausedPresence();
                    break;
                }
                break;

            case NotificationType.TrackChanged:
                UpdatePlayedPresence(songName, songArtist, duration, 0);
                break;
            }
        }