예제 #1
0
파일: YAWIP.cs 프로젝트: lyserbin/YAWIP
    void work()
    {
        uint refreshrate = (uint)spinRefreshRate.Value;
        string tmp, currentsong = string.Empty;

        switch (currentWork) {
        case WorkType.VLC:
            #region VLC
            string hostname = txtVlcHostname.Text;
            uint port = (uint)spinVlcPort.Value;
            string password = txtVlcPassword.Text;
            VlcController conn;

            try
            {
                conn = new VlcController(hostname, port);
                conn.Authenticate(password);
                if (!conn.Authenticated)
                {
                    Application.Invoke(delegate{ SetStatus("Wrong password, please retry!");});
                    stop();
                }

                Application.Invoke(delegate{ SetStatus("VLC worker running");});

                while (true)
                {
                    tmp = conn.GetCurrentSongTitle();
                    if(tmp!= currentsong)
                    {
                        currentsong = tmp;
                        File.WriteAllText(filepath, tmp);
                    }
                    Thread.Sleep ((int)refreshrate);
                }
            }
            catch(SocketException ex)
            {
                Application.Invoke(delegate{ SetStatus("Can't connect to the VLC server / Connection aborted by the server");});
                stop();
            }

            break;
            #endregion
        case WorkType.Spotify:
            #region Spotify
            spotify = new SpotifyLocalAPI();

            if (!SpotifyLocalAPI.IsSpotifyRunning())
            {
                Application.Invoke(delegate{ SetStatus("Spotify isn't running!");});
                stop();
            }
            else if (!SpotifyLocalAPI.IsSpotifyWebHelperRunning())
            {
                Application.Invoke(delegate{ SetStatus("SpotifyWebHelper isn't running!");});
                stop();
            }
            else if (!spotify.Connect())
            {
                Application.Invoke(delegate{ SetStatus("Can't connect to the SpotifyWebHelper.");});
                stop();
            }

            Application.Invoke(delegate{ SetStatus("Spotify worker running");});

            while (true)
            {
                StatusResponse status =  spotify.GetStatus();
                if(status != null && status.Track != null)
                {
                    tmp = status.Track.TrackResource.Uri;

                    if(tmp != currentsong)
                    {
                        string format, formatted;

                        currentsong = tmp;

                        format = txtSpotifyFormat.Text;
                        format = format.Replace("%t", FormatterCodes.Title);
                        format = format.Replace("%a", FormatterCodes.Artist);
                        format = format.Replace("%A", FormatterCodes.Album);

                        formatted = format.Replace(FormatterCodes.Title, status.Track.TrackResource.Name);
                        formatted = formatted.Replace(FormatterCodes.Artist, status.Track.ArtistResource.Name);
                        formatted = formatted.Replace(FormatterCodes.Album, status.Track.AlbumResource.Name);

                        File.WriteAllText(filepath, formatted);
                    }
                }

                Thread.Sleep ((int)refreshrate);
            }
            #endregion
        default:
            Application.Invoke (delegate {SetStatus ("Error: Invalid work selected");});
            stop ();
            break;
        }
    }
예제 #2
0
파일: YAWIP.cs 프로젝트: keefehiggins/YAWIP
    void work()
    {
        uint refreshrate = (uint)spinRefreshRate.Value;
        string tmp, currentsong;

        switch (currentWork) {
        case WorkType.VLC:
            #region VLC
            string hostname = txtVlcHostname.Text;
            uint port = (uint)spinVlcPort.Value;
            string password = txtVlcPassword.Text;
            VlcController conn;

            try
            {
                conn = new VlcController(hostname, port);
                conn.Authenticate(password);
                if (!conn.Authenticated)
                {
                    Application.Invoke(delegate{ SetStatus("Wrong password, please retry!");});
                    stop();
                }

                Application.Invoke(delegate{ SetStatus("VLC worker running");});

                while (true)
                {
                    tmp = conn.GetCurrentSongTitle();
                    File.WriteAllText(filepath, tmp);
                    Thread.Sleep ((int)refreshrate);
                }
            }
            catch(SocketException ex)
            {
                Application.Invoke(delegate{ SetStatus("Can't connect to the VLC server / Connection aborted by the server");});
                stop();
            }

            break;
            #endregion
        case WorkType.Spotify:
            #region Spotify
            Application.Invoke(delegate{ SetStatus("Spotify worker running");});
            while (true)
            {
                Thread.Sleep ((int)refreshrate);
            }
            #endregion
        default:
            Application.Invoke (delegate {SetStatus ("Error: Invalid work selected");});
            stop ();
            break;
        }
    }