// 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, NotificationType type)
        {
            // perform some action depending on the notification type
            switch (type)
            {
            /*
             * case NotificationType.NowPlayingListChanged:
             *  loadNowPlayingList();
             *  break;
             */
            /*
             * case NotificationType.RatingChanged:
             *  string ratingStr = mbApiInterface.Library_GetFileTag(sourceFileUrl, MetaDataType.Rating);
             *
             *  MessageBox.Show(sourceFileUrl + " " + ratingStr);
             *
             *  double rating = double.Parse(ratingStr);
             *
             *  TagLib.Id3v2.Tag.DefaultVersion = 3;
             *  TagLib.Id3v2.Tag.ForceDefaultVersion = true;
             *
             *  TagLib.File file = TagLib.File.Create(sourceFileUrl);
             *
             *  TagLib.Tag Tag = file.GetTag(TagTypes.Id3v2);
             *  TagLib.Id3v2.PopularimeterFrame frame = TagLib.Id3v2.PopularimeterFrame.Get((TagLib.Id3v2.Tag)Tag, "WindowsUser", true);
             *  frame.Rating = (byte)(255 * rating/5.0);
             *  file.Save();
             *  MessageBox.Show(sourceFileUrl + " " + ratingStr);
             *  break;
             */
            case NotificationType.TrackChanged:
//                    string artist = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist);
//                    MessageBox.Show(sourceFileUrl);

                if (!isVideo(sourceFileUrl))
                {
                    stopCurrentVlc();
                    alreadyPlayedMusicCount++;

                    return;
                }

                break;

            case NotificationType.PlayStateChanged:
                //MessageBox.Show("PlayStateChanged:" + mbApiInterface.Player_GetPlayState());
                //Only when stop event occurs after video play started(and stop event occured)
                if (prePlayState == PlayState.Stopped && mbApiInterface.Player_GetPlayState() == PlayState.Stopped)
                {
                    stopCurrentVlc();
                }
                prePlayState = mbApiInterface.Player_GetPlayState();
                // MessageBox.Show(mbApiInterface.Player_GetPlayState() + "");
                break;
            }
        }
        public void ReceiveNotification(string sourceFileUrl, NotificationType type)
        {
            if (mediaChannel != null)
            {
                switch (type)
                {
                case NotificationType.PlayStateChanged:

                    //Play and pause the chromecast from the MB player
                    if (mediaChannel.Status != null)
                    {
                        switch (mbApiInterface.Player_GetPlayState())
                        {
                        case PlayState.Paused:
                            mediaChannel.PauseAsync().WaitWithoutException();
                            break;

                        case PlayState.Playing:
                            mediaChannel.PlayAsync().WaitWithoutException();
                            break;
                        }
                    }

                    break;

                case NotificationType.NowPlayingListChanged:
                    //natural = false;
                    //progressTimer.Enabled = false;
                    break;

                case NotificationType.PluginStartup:
                    break;

                case NotificationType.VolumeLevelChanged:
                    break;

                case NotificationType.TrackChanged:

                    if (!PrerequisitesMet())
                    {
                        return;
                    }

                    fileDeletionTimer.Enabled = false;
                    fileDeletionTimer.Enabled = true;

                    CalculateHash(mbApiInterface.NowPlaying_GetFileUrl(), "current").WaitWithoutException();

                    var info = CopySong(sourceFileUrl, songHash.Current).WaitAndUnwrapException();
                    _ = LoadSong(info.Item1, info.Item2);

                    break;
                }
            }
        }
Exemplo n.º 3
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, NotificationType type)
 {
     // perform some action depending on the notification type
     switch (type)
     {
     case NotificationType.PluginStartup:
     case NotificationType.TrackChanged:
     case NotificationType.PlayStateChanged:
         UpdateDiscordPresence(_mbApiInterface.Player_GetPlayState());
         break;
     }
 }
Exemplo n.º 4
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, NotificationType type)
        {
            // perform some action depending on the notification type
            switch (type)
            {
            case NotificationType.PluginStartup:
                // Establish a websocket connection if enabled and initialize the messages.
                config                  = new StaticConfig();
                wsClient                = new WebSocketClient(config);
                trackChangedMessage     = new TrackChangedMessage(mbApiInterface);
                playStateChangedMessage = new PlayStateChangedMessage();
                trackTimeTimer          = new TrackTimeTimer(mbApiInterface, wsClient);
                break;

            case NotificationType.TrackChanged:
                trackChangedMessage.Send(wsClient);
                break;

            case NotificationType.PlayStateChanged:
                switch (mbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                    playStateChangedMessage.Send(wsClient, true);
                    trackTimeTimer.Start();
                    break;

                case PlayState.Paused:
                case PlayState.Stopped:
                    playStateChangedMessage.Send(wsClient, false);
                    trackTimeTimer.Stop();
                    break;
                }
                break;
            }
        }
Exemplo n.º 5
0
        private void SetPlayerState()
        {
            switch (mbApiInterface.Player_GetPlayState())
            {
            case PlayState.Playing:
                systemMediaControls.PlaybackStatus = MediaPlaybackStatus.Playing;
                if (!systemMediaControls.IsEnabled)
                {
                    systemMediaControls.IsEnabled = true;
                }
                break;

            case PlayState.Paused:
                systemMediaControls.PlaybackStatus = MediaPlaybackStatus.Paused;
                break;

            case PlayState.Undefined:
                systemMediaControls.PlaybackStatus = MediaPlaybackStatus.Stopped;
                systemMediaControls.IsEnabled      = false;
                break;

            case PlayState.Loading:
                systemMediaControls.PlaybackStatus = MediaPlaybackStatus.Changing;
                break;

            case PlayState.Stopped:
                systemMediaControls.PlaybackStatus = MediaPlaybackStatus.Stopped;
                break;
            }
        }
Exemplo n.º 6
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, NotificationType type)
        {
            // perform some action depending on the notification type
            switch (type)
            {
            case NotificationType.PluginStartup:
                // perform startup initialisation
                switch (mbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                    Console.WriteLine("//////////////////////////////////////////\n//////////////////////////////");
                    MessageBox.Show("Error Message", "Error Title", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;

                case PlayState.Paused:
                    // ...
                    break;
                }
                break;

            case NotificationType.TrackChanged:
                string artist = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist);
                // ...
                break;
            }
        }
Exemplo n.º 7
0
        public void ReceiveNotification(string sourceFileUrl, NotificationType type)
        {
            switch (type)
            {
            case NotificationType.PluginStartup:
            case NotificationType.PlayStateChanged:
            case NotificationType.TrackChanged:
                switch (mbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                    UpdatePresencePlayState("playing", settings.ShowTime, settings.ShowRemainingTime);
                    break;

                case PlayState.Paused:
                    UpdatePresencePlayState("paused", false, false);
                    break;

                case PlayState.Stopped:
                    UpdatePresencePlayState("stopped", false, false);
                    break;
                }
                string imageTag         = settings.ImageUseAssetKey ? ReplaceTags(settings.ImageAssetKey, padding: false) : "musicbee";
                string imageDescription = ReplaceTags(settings.ImageDetail);
                string topLine          = ReplaceTags(settings.TopLine);
                string bottomLine       = ReplaceTags(settings.BottomLine);
                UpdatePresenceInfoState(imageTag, topLine, bottomLine, imageDescription);
                UpdatePresenceTrackNumber(settings.ShowTrackNumber);
                discordRpcClient.SetPresence(presence);
                break;
            }
        }
Exemplo n.º 8
0
        public void ReceiveNotification(string sourceFileUrl, NotificationType type)
        {
            switch (type)
            {
            case NotificationType.PluginStartup:
                switch (MBApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                case PlayState.Paused:
                    break;
                }
                break;

            case NotificationType.TrackChanged:
                /*
                 * using (var albumArtBMP = new Bitmap(hue.getAlbumArt(@MBApiInterface.NowPlaying_GetFileUrl()))) {
                 *
                 *  if (Settings.Instance.AverageColor && !stop) {
                 *      var rgbList = hue.getRGBAverage(albumArtBMP, int.Parse(Settings.Instance.QualitySetting));
                 *      var xy = hue.ToXYZ(rgbList[0], rgbList[1], rgbList[2]);
                 *      foreach (string lightName in Settings.Instance.HueLights) {
                 *          new LightStateBuilder().For(lights[lightName]).XYCoordinates(xy[0], xy[1]).Apply();
                 *
                 *      }
                 *  }
                 *  if (Settings.Instance.ColorPalette) {
                 *      List<Tuple<double, double>> colors = new List<Tuple<double, double>>();
                 *      var palette = hue.getColorPalette(albumArtBMP, 8, int.Parse(Settings.Instance.QualitySetting));
                 *      foreach (string str in palette) {
                 *          int red = hue.getRed(str);
                 *          int green = hue.getGreen(str);
                 *          int blue = hue.getBlue(str);
                 *          var xy = hue.ToXYZ(red, green, blue);
                 *          colors.Add(Tuple.Create((double)xy[0], (double)xy[1]));
                 *      }
                 *      if (palette.Count == 0) {
                 *          var xyWhite = hue.ToXYZ(255, 255, 255);
                 *          colors.Add(Tuple.Create((double)xyWhite[0], (double)xyWhite[1]));
                 *      }
                 *
                 *      maxRange = 0;
                 *      aTimer.Dispose();
                 *      //System.Threading.Thread.Sleep(1000);
                 *      aTimer = new System.Timers.Timer();
                 *      aTimer.Stop();
                 *      aTimer.Elapsed += (object s, ElapsedEventArgs a) => sendColorsTimer(colors, colors.Count);
                 *      aTimer.Start();
                 *      aTimer.Interval = 7000;
                 *      aTimer.Enabled = true;
                 *
                 *
                 *  }
                 *
                 * }
                 */
                break;
            }
        }
Exemplo n.º 9
0
        private void systemMediaControls_ButtonPressed(SystemMediaTransportControls smtc, SystemMediaTransportControlsButtonPressedEventArgs args)
        {
            switch (args.Button)
            {
            case SystemMediaTransportControlsButton.Stop:
                mbApiInterface.Player_Stop();
                break;

            case SystemMediaTransportControlsButton.Play:
                if (mbApiInterface.Player_GetPlayState() != PlayState.Playing)
                {
                    mbApiInterface.Player_PlayPause();
                }
                break;

            case SystemMediaTransportControlsButton.Pause:
                if (mbApiInterface.Player_GetPlayState() != PlayState.Paused)
                {
                    mbApiInterface.Player_PlayPause();
                }
                break;

            case SystemMediaTransportControlsButton.Next:
                mbApiInterface.Player_PlayNextTrack();
                break;

            case SystemMediaTransportControlsButton.Previous:
                mbApiInterface.Player_PlayPreviousTrack();
                break;

            case SystemMediaTransportControlsButton.Rewind:
                break;

            case SystemMediaTransportControlsButton.FastForward:
                break;

            case SystemMediaTransportControlsButton.ChannelUp:
                mbApiInterface.Player_SetVolume(mbApiInterface.Player_GetVolume() + 0.05F);
                break;

            case SystemMediaTransportControlsButton.ChannelDown:
                mbApiInterface.Player_SetVolume(mbApiInterface.Player_GetVolume() - 0.05F);
                break;
            }
        }
        public void ReceiveNotification(string sourceFileUrl, NotificationType type)
        {
            string artist      = MbApiInterface.NowPlaying_GetFileTag(MetaDataType.AlbumArtist);
            string trackArtist = MbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist);
            string trackTitle  = MbApiInterface.NowPlaying_GetFileTag(MetaDataType.TrackTitle);
            string album       = MbApiInterface.NowPlaying_GetFileTag(MetaDataType.Album);
            string duration    = MbApiInterface.NowPlaying_GetFileProperty(FilePropertyType.Duration);
            int    volume      = Convert.ToInt32(MbApiInterface.Player_GetVolume() * 100.0f);
            int    position    = MbApiInterface.Player_GetPosition() / 1000;

            if (string.IsNullOrEmpty(artist))
            {
                artist = "[artist empty]";
            }

            switch (type)
            {
            case NotificationType.PlayStateChanged:
                switch (MbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                    UpdatePresence(artist, trackArtist, trackTitle, album, duration, true, position, volume);
                    break;

                case PlayState.Paused:
                    UpdatePresence(artist, trackArtist, trackTitle, album, duration, false, 0, volume);
                    break;
                }

                break;

            case NotificationType.TrackChanged:
                UpdatePresence(artist, trackArtist, trackTitle, album, duration, true, 0, volume, true);
                break;

            case NotificationType.VolumeLevelChanged:
                if (MbApiInterface.Player_GetPlayState() == PlayState.Playing)
                {
                    UpdatePresence(artist, trackArtist, trackTitle, album, duration, true, position, volume);
                }
                break;
            }
        }
Exemplo n.º 11
0
        public void ReceiveNotification(string src, NotificationType type)
        {
            if (type == NotificationType.PlayerScrobbleChanged)
            {
                if (Api.Player_GetScrobbleEnabled())
                {
                    Api.Player_SetScrobbleEnabled(false);
                }
                return;
            }

            if (type != NotificationType.TrackChanged && type != NotificationType.PlayStateChanged)
            {
                return;
            }

            var title       = Api.NowPlaying_GetFileTag(Settings.GetTag("ScrobbleBee-Title", MetaDataType.TrackTitle));
            var artist      = Api.NowPlaying_GetFileTag(Settings.GetTag("ScrobbleBee-Artist", MetaDataType.Artist));
            var album       = Api.NowPlaying_GetFileTag(Settings.GetTag("ScrobbleBee-Album", MetaDataType.Album));
            var albumArtist = Api.NowPlaying_GetFileTag(Settings.GetTag("ScrobbleBee-AlbumArtist", MetaDataType.AlbumArtist));
            var duration    = Api.NowPlaying_GetDuration();

            switch (type)
            {
            case NotificationType.TrackChanged:
                TryScrobble(lastTitle, lastArtist, lastAlbum, lastAlbumArtist, lastDuration);
                LastFm.Update(title, artist, album, albumArtist, duration);

                hasScrobbled = duration < 30000;
                started      = DateTime.UtcNow;
                played       = 0;

                lastTitle       = title;
                lastArtist      = artist;
                lastAlbum       = album;
                lastAlbumArtist = albumArtist;
                lastDuration    = duration;
                break;

            case NotificationType.PlayStateChanged:
                switch (Api.Player_GetPlayState())
                {
                case PlayState.Playing:
                    started = DateTime.UtcNow;
                    break;

                case PlayState.Paused:
                case PlayState.Stopped:
                    TryScrobble(title, artist, album, albumArtist, duration);
                    break;
                }
                break;
            }
        }
Exemplo n.º 12
0
        public void ReceiveNotification(string sourceFileUrl, NotificationType type)
        {
            switch (type)
            {
            case NotificationType.TrackChanged:
            case NotificationType.PlayStateChanged:
                if (mbApiInterface.Player_GetPlayState() == PlayState.Playing)
                {
                    SendRequest();
                }

                break;
            }
        }
Exemplo n.º 13
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;
            }
        }
Exemplo n.º 14
0
        public void ReceiveNotification(string src, NotificationType type)
        {
            if (type != NotificationType.TrackChanged && type != NotificationType.PlayStateChanged)
            {
                return;
            }

            string title    = Api.NowPlaying_GetFileTag(Settings.Title);
            string artist   = Api.NowPlaying_GetFileTag(Settings.Artist);
            string album    = Api.NowPlaying_GetFileTag(Settings.Album);
            int    duration = Api.NowPlaying_GetDuration();

            switch (type)
            {
            case NotificationType.TrackChanged:
                TryScrobble(lastTitle, lastArtist, lastAlbum, lastDuration);
                LastFM.Update(title, artist, album, (duration / 1000).ToString());

                hasScrobbled = duration < 30000;
                started      = DateTime.UtcNow;
                played       = 0;

                lastTitle    = title;
                lastArtist   = artist;
                lastAlbum    = album;
                lastDuration = duration;
                break;

            case NotificationType.PlayStateChanged:
                switch (Api.Player_GetPlayState())
                {
                case PlayState.Playing:
                    started = DateTime.UtcNow;
                    break;

                case PlayState.Paused:
                case PlayState.Stopped:
                    TryScrobble(title, artist, album, duration);
                    break;
                }
                break;
            }
        }
        // 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, NotificationType type)
        {
            string artist     = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist);
            string trackTitle = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.TrackTitle);
            string duration   = mbApiInterface.NowPlaying_GetFileProperty(FilePropertyType.Duration);
            // mbApiInterface.NowPlaying_GetDuration();
            int    position = mbApiInterface.Player_GetPosition();
            string song     = artist + " - " + trackTitle;

            if (string.IsNullOrEmpty(artist))
            {
                song = trackTitle;
            }
            // perform some action depending on the notification type
            PlayState state = mbApiInterface.Player_GetPlayState();

            switch (type)
            {
            case NotificationType.PluginStartup:
            // perform startup initialisation
            case NotificationType.PlayStateChanged:
                switch (state)
                {
                case PlayState.Playing:
                    UpdatePresence(song, duration, position / 1000, state);
                    break;

                case PlayState.Paused:
                    UpdatePresence(song, duration, 0, state: state);
                    break;

                case PlayState.Stopped:
                    UpdatePresence(song, duration, 0, state);
                    break;
                }
                break;

            case NotificationType.TrackChanged:
                UpdatePresence(song, duration, 0, state);
                break;
            }
        }
Exemplo n.º 16
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, NotificationType type)
        {
            // perform some action depending on the notification type
            switch (type)
            {
            case NotificationType.PluginStartup:
                // perform startup initialisation
                switch (mbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                case PlayState.Paused:
                    // ...
                    break;
                }
                break;

            case NotificationType.TrackChanged:
                string artist = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist);
                // ...
                break;
            }
        }
Exemplo n.º 17
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, NotificationType type)
        {
            // perform some action depending on the notification type
            switch (type)
            {
            case NotificationType.PluginStartup:

                StartServer();
                MbApiInstance.Instance.MusicBeeApiInterface = mbApiInterface;

                switch (mbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                case PlayState.Paused:
                    // ...
                    break;
                }
                break;

            case NotificationType.TrackChanged:
                break;
            }
        }
        // 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, NotificationType type)
        {
            string artist     = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist);
            string trackTitle = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.TrackTitle);
            string album      = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Album);
            string duration   = mbApiInterface.NowPlaying_GetFileProperty(FilePropertyType.Duration);
            // mbApiInterface.NowPlaying_GetDuration();
            int position = mbApiInterface.Player_GetPosition();

            // Check if there isn't an artist for the current song. If so, replace it with "(unknown artist)".
            if (string.IsNullOrEmpty(artist))
            {
                artist = "(unknown artist)";
            }
            // perform some action depending on the notification type
            switch (type)
            {
            case NotificationType.PluginStartup:
            // perform startup initialisation
            case NotificationType.PlayStateChanged:
                switch (mbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                    UpdatePresence(artist, trackTitle, album, duration, true);
                    break;

                case PlayState.Paused:
                    UpdatePresence(artist, trackTitle, album, duration, false);
                    break;
                }
                break;

            case NotificationType.TrackChanged:
                UpdatePresence(artist, trackTitle, album, duration, true);
                break;
            }
        }
Exemplo n.º 19
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, NotificationType type)
        {
            // perform some action depending on the notification type
            switch (type)
            {
            case NotificationType.PluginStartup:
                // perform startup initialisation
                _manager = new Manager(mbApiInterface);
                _track   = GetTrack();
                _manager.UpdateTrack(_track);
                //_timer = new Timer(100);
                //_timer.Elapsed += _timer_Elapsed;
                switch (mbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                    // _timer.Start();
                    _manager.StartTimer();
                    break;
                }
                //if (ChapterListMB.Properties.Settings.Default.StartWithMusicBee)
                //    OnMenuClicked(null, null);
                break;

            case NotificationType.TrackChanged:
                if (_mainForm == null && _mbPanel == null)
                {
                    return;
                }
                RepeatSection.Clear();
                _currentChapter = null;
                _track          = GetTrack();
                _manager.UpdateTrack(_track);
                _mainForm?.Invoke(_mainForm.UpdateTrackDelegate, _track);
                if (mbApiInterface.Player_GetPlayState() == PlayState.Playing)
                {
                    _manager.StartTimer();
                }
                break;

            case NotificationType.TrackChanging:
                //if (!_timer.Enabled) _timer.Stop();
                _manager.StopTimer();
                break;

            case NotificationType.PlayStateChanged:
                //if (_track == null) return;
                switch (mbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                    //if (!_timer.Enabled) _timer.Start();
                    _manager.StartTimer();
                    break;

                case PlayState.Paused:
                    //if (_timer.Enabled) _timer.Stop();
                    _manager.StopTimer();
                    break;

                case PlayState.Stopped:
                    //if (_timer.Enabled) _timer.Stop();
                    _manager.StopTimer();
                    break;

                case PlayState.Undefined:
                    //if (_timer.Enabled) _timer.Stop();
                    _manager.StopTimer();
                    break;
                }
                break;
            }
        }
Exemplo n.º 20
0
        public void ReceiveNotification(string sourceFileUrl, NotificationType type)
        {
            // perform some action depending on the notification type
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (type)
            {
            case NotificationType.PluginStartup:
                // while (!Debugger.IsAttached) System.Threading.Thread.Sleep(1);
                try
                {
                    try
                    {
                        _settings = JsonConvert.DeserializeObject <SettingsObj>(File.ReadAllText(SettingsPath));
                    }
                    catch (Exception)
                    {
                        _settings = new SettingsObj
                        {
                            BorderColor  = Color.Black,
                            Color1       = Color.GhostWhite,
                            Color2       = Color.LightGray,
                            FontActual   = new Font(FontFamily.GenericSansSerif, 34.0f, FontStyle.Regular, GraphicsUnit.Point),
                            GradientType = 1
                        };
                    }

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);

                    StartupMenuItem();
                    if (!_settings.HideOnStartup)
                    {
                        StartupForm();
                    }

                    if (_timer != null && _timer.Enabled)
                    {
                        _timer.Enabled = false;
                    }
                    _timer = new Timer(UpdateIntervalMs)
                    {
                        AutoReset = false
                    };
                    _timer.Elapsed += TimerTick;
                    _timer.Start();
                }
                catch (Exception e)
                {
                    _mbApiInterface.MB_Trace(e.ToString());
                }
                break;

            case NotificationType.PlayStateChanged:
                UpdatePlayState(_mbApiInterface.Player_GetPlayState());
                break;

            case NotificationType.NowPlayingLyricsReady:
                try
                {
                    UpdateLyrics();
                }
                catch (Exception e)
                {
                    _mbApiInterface.MB_Trace(e.ToString());
                }
                break;

            case NotificationType.TagsChanged:
                try
                {
                    UpdateLyrics();
                }
                catch (Exception e)
                {
                    _mbApiInterface.MB_Trace(e.ToString());
                }
                break;
            }
        }
Exemplo n.º 21
0
 /// <inheritdoc />
 public bool Play()
 {
     return(_api.Player_GetPlayState() != PlayState.Playing && _api.Player_PlayPause());
 }
Exemplo n.º 22
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, NotificationType type)
        {
            // perform some action depending on the notification type
            switch (type)
            {
            case NotificationType.PluginStartup:
            case NotificationType.TrackChanged:
            case NotificationType.PlayStateChanged:
                UpdateDiscordPresence(_mbApiInterface.Player_GetPlayState());
                break;

            case NotificationType.TrackChanging:
                break;

            case NotificationType.AutoDjStarted:
                break;

            case NotificationType.AutoDjStopped:
                break;

            case NotificationType.VolumeMuteChanged:
                break;

            case NotificationType.VolumeLevelChanged:
                break;

            case NotificationType.NowPlayingListChanged:
                break;

            case NotificationType.NowPlayingListEnded:
                break;

            case NotificationType.NowPlayingArtworkReady:
                break;

            case NotificationType.NowPlayingLyricsReady:
                break;

            case NotificationType.TagsChanging:
                break;

            case NotificationType.TagsChanged:
                break;

            case NotificationType.RatingChanging:
                break;

            case NotificationType.RatingChanged:
                break;

            case NotificationType.PlayCountersChanged:
                break;

            case NotificationType.ScreenSaverActivating:
                break;

            case NotificationType.ShutdownStarted:
                break;

            case NotificationType.EmbedInPanel:
                break;

            case NotificationType.PlayerRepeatChanged:
                break;

            case NotificationType.PlayerShuffleChanged:
                break;

            case NotificationType.PlayerEqualiserOnOffChanged:
                break;

            case NotificationType.PlayerScrobbleChanged:
                break;

            case NotificationType.ReplayGainChanged:
                break;

            case NotificationType.FileDeleting:
                break;

            case NotificationType.FileDeleted:
                break;

            case NotificationType.ApplicationWindowChanged:
                break;

            case NotificationType.StopAfterCurrentChanged:
                break;

            case NotificationType.LibrarySwitched:
                break;

            case NotificationType.FileAddedToLibrary:
                break;

            case NotificationType.FileAddedToInbox:
                break;

            case NotificationType.SynchCompleted:
                break;

            case NotificationType.DownloadCompleted:
                break;

            case NotificationType.MusicBeeStarted:
                break;
            }
        }
Exemplo n.º 23
0
        public void ReceiveNotification(string sourceFileUrl, NotificationType type)
        {
            switch (type)
            {
            case NotificationType.PlayStateChanged:


                //Play and pause the chromecast from the MB player
                if (csSender != null)
                {
                    switch (mbApiInterface.Player_GetPlayState())
                    {
                    case PlayState.Paused:
                        csSender.GetChannel <IMediaChannel>().PauseAsync().WaitWithoutException();
                        break;

                    case PlayState.Playing:
                        csSender.GetChannel <IMediaChannel>().PlayAsync().WaitWithoutException();
                        break;
                    }

                    //csSender.GetChannel<IMediaChannel>().SeekAsync(mbApiInterface.Player_GetPosition() / 1000).WaitWithoutException();
                }

                break;

            case NotificationType.PluginStartup:
                break;

            case NotificationType.VolumeLevelChanged:
                break;

            case NotificationType.TrackChanged:

                if (!PrerequisitesMet())
                {
                    return;
                }


                try
                {
                    Task.Run(() =>
                    {
                        //Get the songname and format it into half of the url
                        StringBuilder songName = new StringBuilder(@mbApiInterface.NowPlaying_GetFileUrl());
                        songName.Replace(library, "");
                        songName.Replace(@"\", @"/");

                        mediaChannel.LoadAsync(
                            new MediaInformation()
                        {
                            ContentId  = mediaContentURL + HttpUtility.UrlPathEncode(songName.ToString()),        //Where the media is located
                            StreamType = StreamType.Buffered,
                            Metadata   = new MusicTrackMediaMetadata
                            {
                                Artist    = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist),      //Shows the Artist
                                Title     = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.TrackTitle),  //Shows the Track Title
                                AlbumName = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Album),
                            },
                        });
                    });
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }



                break;
            }
        }
Exemplo n.º 24
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, NotificationType type)
        {
            // activate video only if valid extention
            string[] ext     = extConf.Split(' ');
            bool     tmpFlag = false;

            foreach (string i in ext)
            {
                if (sourceFileUrl.EndsWith(i))
                {
                    tmpFlag = true;
                }
            }
            // perform some action depending on the notification type
            switch (type)
            {
            case NotificationType.PlayStateChanged:
                if (tmpFlag)
                {
                    switch (mbApiInterface.Player_GetPlayState())
                    {
                    case PlayState.Playing:
                        int    tmp = mbApiInterface.Player_GetPosition();
                        double sec = tmp / 1000.0;
                        Program.MpvLoadFile2(sec.ToString(), 0);

                        break;

                    case PlayState.Paused:
                        Program.MpvLoadFile2("", 1);
                        break;
                    }
                }
                else
                {
                    // clear MPV but still keep open
                    Program.MpvLoadFile2("", 2);
                }
                break;

            case NotificationType.PluginStartup:
                // perform startup initialisation
                break;

            case NotificationType.TrackChanged:
                switch (mbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                    if (tmpFlag)
                    {
                        Program.MainHack(sourceFileUrl);
                        var t = Task.Factory.StartNew(() =>
                        {
                            return(Task.Factory.StartNew(() =>
                            {
                                Task.Delay(3000).Wait();
                                Program.MpvLoadFile2((mbApiInterface.Player_GetPosition() / 1000.0).ToString(), 0);
                            }));
                        });
                        t.Wait();
                    }
                    else
                    {
                        Program.MpvLoadFile2("", 2);
                    }
                    break;

                case PlayState.Paused:
                    break;
                }
                break;
            }
        }
        // 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, NotificationType type)
        {
            _currentTrackUrl = sourceFileUrl;

            switch (type)
            {
            case NotificationType.PlayStateChanged:
                if (!IsAudiobook(_currentTrackUrl))
                {
                    return;
                }

                switch (_mbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                    if (_mbApiInterface.Player_GetPosition() == 0)
                    {
                        LoadSavedPosition();
                    }

                    _playingTimer.Start();
                    break;

                case PlayState.Paused:
                    _playingTimer.Stop();
                    SavePosition();
                    break;

                case PlayState.Stopped:
                    _playingTimer.Stop();
                    break;
                }

                break;

            case NotificationType.TrackChanging:
                if (!IsAudiobook(_currentTrackUrl))
                {
                    return;
                }

                _playingTimer.Stop();
                break;

            case NotificationType.TrackChanged:
                if (!IsAudiobook(_currentTrackUrl))
                {
                    return;
                }

                // Necessary because Player_SetPosition is triggering this event, causing an infinite loop.
                if (CurrentTrackUrl() == _currentTrackUrl)
                {
                    return;
                }

                Thread.Sleep(500);
                LoadSavedPosition();
                _playingTimer.Start();
                break;
            }
        }
Exemplo n.º 26
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, NotificationType type)
        {
            //stopwatch.Start();

            //query the duration of the track when the plugin receives a track change event and using a timer query the play position via the api every second for example
            // perform some action depending on the notification type
            switch (type)
            {
            case NotificationType.PluginStartup:
                // perform startup initialisation


                switch (mbApiInterface.Player_GetPlayState())
                {
                case PlayState.Playing:
                case PlayState.Paused:
                    // ...case NotificationType.TrackChanged:

                    break;
                }
                break;

            case NotificationType.TrackChanged:

                using (var albumArtBMP = new Bitmap(hue.getAlbumArt(@mbApiInterface.NowPlaying_GetFileUrl())))
                {
                    if (Settings.Instance.AverageColor && !stop)
                    {
                        var rgbList = hue.getRGBAverage(albumArtBMP, int.Parse(Settings.Instance.QualitySetting));
                        var xy      = hue.ToXYZ(rgbList[0], rgbList[1], rgbList[2]);
                        foreach (string lightName in Settings.Instance.HueLights)
                        {
                            new LightStateBuilder().For(lights[lightName]).XYCoordinates(xy[0], xy[1]).Apply();
                        }
                    }
                    if (Settings.Instance.ColorPalette)
                    {
                        List <Tuple <double, double> > colors = new List <Tuple <double, double> >();
                        //Thread thread;


                        var palette = hue.getColorPalette(albumArtBMP, 8, int.Parse(Settings.Instance.QualitySetting));
                        foreach (string str in palette)
                        {
                            int red   = hue.getRed(str);
                            int green = hue.getGreen(str);
                            int blue  = hue.getBlue(str);
                            var xy    = hue.ToXYZ(red, green, blue);
                            colors.Add(Tuple.Create((double)xy[0], (double)xy[1]));
                        }
                        if (palette.Count == 0)
                        {
                            var xyWhite = hue.ToXYZ(255, 255, 255);
                            colors.Add(Tuple.Create((double)xyWhite[0], (double)xyWhite[1]));
                        }

                        //Below is the code for the thread version of sending the color. This
                        //has way more cpu usage

                        //threadStop = !threadStop;
                        //System.Threading.Thread.Sleep(500);
                        //thread = new Thread(() => sendColorsThread(colors, colors.Count));
                        //thread.IsBackground = true;
                        //thread.Start();

                        maxRange = 0;
                        aTimer.Dispose();
                        //System.Threading.Thread.Sleep(1000);
                        aTimer = new System.Timers.Timer();
                        aTimer.Stop();
                        aTimer.Elapsed += (object s, ElapsedEventArgs a) => sendColorsTimer(colors, colors.Count);
                        aTimer.Start();
                        aTimer.Interval = 7000;
                        aTimer.Enabled  = true;
                    }
                }

                break;
            }
        }
        // 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, NotificationType type)
        {
            // perform some action depending on the notification type
            switch (type)
            {
            case NotificationType.PluginStartup:

                if (device_ == null)
                {
                    settings_ = new Settings(mbApiInterface_.Setting_GetPersistentStoragePath(), this);

                    connectDevice();

                    settings_.openSettings();
                    pluginObject_ = this;

                    //Create an event to signal the timeout count threshold in the
                    // timer callback.
                    autoEvent = new AutoResetEvent(false);

                    // Create an inferred delegate that invokes methods for the timer.
                    TimerCallback tcb = refreshLoop;

                    // Create a timer that signals the delegate to invoke
                    // CheckStatus after one second, and every 1/4 second
                    // thereafter.
                    timer_ = new System.Threading.Timer(tcb, autoEvent, 1000, 100);
                }
                eventHappened_ = true;
                break;

            case NotificationType.PlayStateChanged:

                if (lcdScreenList_.Count > 0 && lcdScreenList_[0].getName() == "StartupScreen")
                {
                    openScreens();
                }

                stateChanged(mbApiInterface_.Player_GetPlayState());
                getSongData();
                getVolume();
                getSettings();
                eventHappened_ = true;
                timerTime_     = mbApiInterface_.Player_GetPosition();

                break;

            case NotificationType.NowPlayingListChanged:
            case NotificationType.PlayerEqualiserOnOffChanged:
            case NotificationType.PlayerRepeatChanged:
            case NotificationType.PlayerShuffleChanged:
            case NotificationType.AutoDjStarted:
            case NotificationType.AutoDjStopped:
            case NotificationType.NowPlayingArtworkReady:
            case NotificationType.RatingChanged:
            case NotificationType.TrackChanged:
            case NotificationType.VolumeLevelChanged:
            case NotificationType.VolumeMuteChanged:
            case NotificationType.NowPlayingLyricsReady:
                if (lcdScreenList_.Count > 0 && lcdScreenList_[0].getName() == "StartupScreen")
                {
                    openScreens();
                }

                getVolume();
                getSongData();
                getSettings();
                eventHappened_ = true;
                timerTime_     = mbApiInterface_.Player_GetPosition();
                break;
            }
        }
Exemplo n.º 28
0
 private void UpdateTimerElapsedCallback(object sender, ElapsedEventArgs e)
 {
     UpdateDiscordPresence(_mbApiInterface.Player_GetPlayState());
     _updateTimer.Stop();
 }