Example #1
0
        // receive event notifications from MusicBee
        // you need to set about.ReceiveNotificationFlags = PlayerEvents to receive all notifications, and not just the startup event
        public void ReceiveNotification(string sourceFileUrl, Interfaces.Plugin.NotificationType type)
        {
            // perform some action depending on the notification type
            //switch (type)

            if (type != Interfaces.Plugin.NotificationType.PluginStartup)
            {
                return;
            }

            var dataPath = _mbApiInterface.Setting_GetPersistentStoragePath();

            Subsonic.CacheFilename    = Path.Combine(dataPath, "subsonicCache.dat");
            Subsonic.SettingsFilename = Path.Combine(dataPath, "subsonicSettings.dat");

            Subsonic.SendNotificationsHandler.Invoke(Subsonic.Initialize()
                ? Interfaces.Plugin.CallbackType.StorageReady
                : Interfaces.Plugin.CallbackType.StorageFailed);

            //case NotificationType.TrackChanged:
            //    string artist = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist);
            //    // ...
            //    break;
        }
Example #2
0
        // receive event notifications from MusicBee
        // you need to set about.ReceiveNotificationFlags = PlayerEvents to receive all notifications, and not just the startup event
        public void ReceiveNotification(string sourceFileUrl, Interfaces.Plugin.NotificationType type)
        {
            // perform some action depending on the notification type
            switch (type)
            {
            case Interfaces.Plugin.NotificationType.PluginStartup:
                var dataPath = _mbApiInterface.Setting_GetPersistentStoragePath();
                Subsonic.CacheFilename    = Path.Combine(dataPath, "subsonicCache.dat");
                Subsonic.SettingsFilename = Path.Combine(dataPath, "subsonicSettings.dat");

                Subsonic.SendNotificationsHandler.Invoke(Subsonic.Initialize()
                        ? Interfaces.Plugin.CallbackType.StorageReady
                        : Interfaces.Plugin.CallbackType.StorageFailed);
                break;

            case Interfaces.Plugin.NotificationType.TagsChanged:
                //var tags = new List<Interfaces.Plugin.MetaDataType>
                //{
                //    Interfaces.Plugin.MetaDataType.Artist,
                //    Interfaces.Plugin.MetaDataType.TrackTitle,
                //    Interfaces.Plugin.MetaDataType.Album,
                //    Interfaces.Plugin.MetaDataType.Year,
                //    Interfaces.Plugin.MetaDataType.TrackNo,
                //    Interfaces.Plugin.MetaDataType.Genre,
                //    Interfaces.Plugin.MetaDataType.Artwork,
                //    Interfaces.Plugin.MetaDataType.DiscNo,
                //    Interfaces.Plugin.MetaDataType.RatingLove,
                //    Interfaces.Plugin.MetaDataType.Rating
                //};

                //Subsonic.GetFileTags(sourceFileUrl, tags.ToArray(), out var results);
                //Subsonic.UpdateTags(results);

                var rating  = Subsonic.GetFileTag(sourceFileUrl, Interfaces.Plugin.MetaDataType.Rating);
                var starred = Subsonic.GetFileTag(sourceFileUrl, Interfaces.Plugin.MetaDataType.RatingLove);
                var id      = Subsonic.GetFileTag(sourceFileUrl, Interfaces.Plugin.MetaDataType.Custom16);

                Subsonic.UpdateRating(id, rating);
                Subsonic.UpdateRatingLove(id, starred);
                break;

            //case Interfaces.Plugin.NotificationType.PlaylistCreated:
            //    // TODO send new playlist to Subsonic Server
            //    string[] filenames;
            //    Subsonic.QueryPlaylistFilesEx(sourceFileUrl, out filenames);

            //    break;

            //case Interfaces.Plugin.NotificationType.PlaylistUpdated:
            //    //TODO check what happens here
            //    string[] filenames1;
            //    Subsonic.QueryPlaylistFilesEx(sourceFileUrl, out filenames1);

            //    break;

            case Interfaces.Plugin.NotificationType.PlaylistDeleted:
                //TODO Delete playlist
                var serverPlaylists  = Subsonic.GetPlaylists();
                var playlistToDelete = serverPlaylists.Where(p => p.Value.Equals(GetPlaylistName(sourceFileUrl)));
                foreach (var item in playlistToDelete)
                {
                    Subsonic.DeletePlaylist(int.Parse(item.Key));
                }
                break;

            case Interfaces.Plugin.NotificationType.PlaylistMoved:
                string[] filenames;
                Subsonic.QueryPlaylistFilesEx(sourceFileUrl, out filenames);

                // Get Song IDs to add to playlist
                var songIds = new List <int>();
                foreach (var filename in filenames)
                {
                    id = Subsonic.GetFileTag(filename, Interfaces.Plugin.MetaDataType.Custom16);
                    if (int.TryParse(id, out var songId))
                    {
                        songIds.Add(songId);
                    }
                }

                Subsonic.CreatePlaylist(GetPlaylistName(sourceFileUrl), songIds);
                break;

                //case NotificationType.TrackChanged:
                //    string artist = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist);
                //    // ...
                //    break;
            }
        }