Ejemplo n.º 1
0
 private static PlayerState GetPlayerState(MpdState mpdState)
 {
     return(mpdState switch
     {
         MpdState.Play => PlayerState.Playing,
         MpdState.Stop => PlayerState.Stopped,
         MpdState.Pause => PlayerState.Paused,
         _ => PlayerState.Unknown
     });
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MpdStatus" /> class.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="repeat">if set to <c>true</c> [repeat].</param>
 /// <param name="random">if set to <c>true</c> [random].</param>
 /// <param name="consume">if set to <c>true</c> [consume].</param>
 /// <param name="single">if set to <c>true</c> [single].</param>
 /// <param name="playlist">The playlist.</param>
 /// <param name="playlistLength">Length of the playlist.</param>
 /// <param name="xFade">The x fade.</param>
 /// <param name="state">The state.</param>
 /// <param name="song">The song.</param>
 /// <param name="songId">The song identifier.</param>
 /// <param name="nextSong">The next song.</param>
 /// <param name="nextSongId">The next song identifier.</param>
 /// <param name="elapsed">The elapsed.</param>
 /// <param name="duration">The duration.</param>
 /// <param name="bitrate">The bitrate.</param>
 /// <param name="audioSampleRate">The audio sample rate.</param>
 /// <param name="audioBits">The audio bits.</param>
 /// <param name="audioChannels">The audio channels.</param>
 /// <param name="updatingDb">The updating database.</param>
 /// <param name="error">The error.</param>
 public MpdStatus(
     int volume,
     bool repeat,
     bool random,
     bool consume,
     bool single,
     int playlist,
     int playlistLength,
     int xFade,
     MpdState state,
     int song,
     int songId,
     int nextSong,
     int nextSongId,
     TimeSpan elapsed,
     TimeSpan duration,
     int bitrate,
     int audioSampleRate,
     int audioBits,
     int audioChannels,
     int updatingDb,
     string error)
 {
     this.Volume          = volume;
     this.Repeat          = repeat;
     this.Random          = random;
     this.Consume         = consume;
     this.Single          = single;
     this.Playlist        = playlist;
     this.PlaylistLength  = playlistLength;
     this.XFade           = xFade;
     this.State           = state;
     this.Song            = song;
     this.SongId          = songId;
     this.NextSong        = nextSong;
     this.NextSongId      = nextSongId;
     this.Elapsed         = elapsed;
     this.Duration        = duration;
     this.Bitrate         = bitrate;
     this.AudioSampleRate = audioSampleRate;
     this.AudioBits       = audioBits;
     this.AudioChannels   = audioChannels;
     this.UpdatingDb      = updatingDb;
     this.Error           = error;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new MpdStatus object.
 /// </summary>
 /// <param name="volume">The current volume of the output.</param>
 /// <param name="repeat">If the playlist is repeated after finish.</param>
 /// <param name="random">If the playlist is played in random order.</param>
 /// <param name="playlist">The version number of the playlist.</param>
 /// <param name="playlistLength">The length of the playlist.</param>
 /// <param name="xFade">The number of seconds crossfaded between song changes.</param>
 /// <param name="state">The state of the MPD.</param>
 /// <param name="song">The index of the currently played song in the playlist.</param>
 /// <param name="songId">The id of the song currently played.</param>
 /// <param name="timeElapsed">The number of seconds already played of the current song.</param>
 /// <param name="timeTotal">The length of the current song in seconds.</param>
 /// <param name="bitrate">The bitrate of the current song.</param>
 /// <param name="audioSampleRate">The audio sample rate of the current song.</param>
 /// <param name="audioBits">The audio bits of the current song.</param>
 /// <param name="audioChannels">The number of audio channels of the current song.</param>
 /// <param name="updatingDb">The number of the update on the MPD database currently running.</param>
 /// <param name="error">An error message, if there is an error.</param>
 public MpdStatus(
     int volume,
     bool repeat,
     bool random,
     int playlist,
     int playlistLength,
     int xFade,
     MpdState state,
     int song,
     int songId,
     int timeElapsed,
     int timeTotal,
     int bitrate,
     int audioSampleRate,
     int audioBits,
     int audioChannels,
     int updatingDb,
     string error
     )
 {
     this.volume          = volume;
     this.repeat          = repeat;
     this.random          = random;
     this.playlist        = playlist;
     this.playlistLength  = playlistLength;
     this.xFade           = xFade;
     this.state           = state;
     this.song            = song;
     this.songId          = songId;
     this.timeElapsed     = timeElapsed;
     this.timeTotal       = timeTotal;
     this.bitrate         = bitrate;
     this.audioSampleRate = audioSampleRate;
     this.audioBits       = audioBits;
     this.audioChannels   = audioChannels;
     this.updatingDb      = updatingDb;
     this.error           = error;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new MpdStatus object.
 /// </summary>
 /// <param name="volume">The current volume of the output.</param>
 /// <param name="repeat">If the playlist is repeated after finish.</param>
 /// <param name="random">If the playlist is played in random order.</param>
 /// <param name="playlist">The version number of the playlist.</param>
 /// <param name="playlistLength">The length of the playlist.</param>
 /// <param name="xFade">The number of seconds crossfaded between song changes.</param>
 /// <param name="state">The state of the MPD.</param>
 /// <param name="song">The index of the currently played song in the playlist.</param>
 /// <param name="songId">The id of the song currently played.</param>
 /// <param name="timeElapsed">The number of seconds already played of the current song.</param>
 /// <param name="timeTotal">The length of the current song in seconds.</param>
 /// <param name="bitrate">The bitrate of the current song.</param>
 /// <param name="audioSampleRate">The audio sample rate of the current song.</param>
 /// <param name="audioBits">The audio bits of the current song.</param>
 /// <param name="audioChannels">The number of audio channels of the current song.</param>
 /// <param name="updatingDb">The number of the update on the MPD database currently running.</param>
 /// <param name="error">An error message, if there is an error.</param>
 public MpdStatus(
 int volume,
 bool repeat,
 bool random,
 int playlist,
 int playlistLength,
 int xFade,
 MpdState state,
 int song,
 int songId,
 int timeElapsed,
 int timeTotal,
 int bitrate,
 int audioSampleRate,
 int audioBits,
 int audioChannels,
 int updatingDb,
 string error
 )
 {
     this.volume = volume;
       this.repeat = repeat;
       this.random = random;
       this.playlist = playlist;
       this.playlistLength = playlistLength;
       this.xFade = xFade;
       this.state = state;
       this.song = song;
       this.songId = songId;
       this.timeElapsed = timeElapsed;
       this.timeTotal = timeTotal;
       this.bitrate = bitrate;
       this.audioSampleRate = audioSampleRate;
       this.audioBits = audioBits;
       this.audioChannels = audioChannels;
       this.updatingDb = updatingDb;
       this.error = error;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Deserializes the specified response text pairs.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <returns>
        /// The deserialized response.
        /// </returns>
        public MpdStatus Deserialize(IReadOnlyList <KeyValuePair <string, string> > response)
        {
            int      volume             = -1;
            bool     repeat             = false;
            bool     random             = false;
            bool     single             = false;
            bool     consume            = false;
            int      playlist           = -1;
            int      playlistLength     = 0;
            int      playlistSong       = -1;
            int      playlistSongId     = -1;
            int      playlistNextSong   = -1;
            int      playlistNextSongId = -1;
            int      bitrate            = 0;
            int      audioSampleRate    = -1;
            int      audioBits          = -1;
            int      audioChannels      = -1;
            int      crossfade          = -1;
            MpdState mpdState           = MpdState.Unknown;
            TimeSpan elapsed;
            TimeSpan duration;
            double   mixrampDb  = -1;
            int      updatingDb = -1;
            string   error      = string.Empty;

            foreach (var keyValuePair in response)
            {
                var value = keyValuePair.Value;
                switch (keyValuePair.Key)
                {
                case VolumeText:
                    int.TryParse(value, out volume);
                    break;

                case RepeatText:
                    repeat = value == "1";
                    break;

                case RandomText:
                    random = value == "1";
                    break;

                case SingleText:
                    single = value == "1";
                    break;

                case ConsumeText:
                    consume = value == "1";
                    break;

                case PlaylistText:
                    int.TryParse(value, out playlist);
                    break;

                case PlaylistlengthText:
                    int.TryParse(value, out playlistLength);
                    break;

                case SongText:
                    int.TryParse(value, out playlistSong);
                    break;

                case SongidText:
                    int.TryParse(value, out playlistSongId);
                    break;

                case NextsongText:
                    int.TryParse(value, out playlistNextSong);
                    break;

                case NextsongidText:
                    int.TryParse(value, out playlistNextSongId);
                    break;

                case BitrateText:
                    int.TryParse(value, out bitrate);
                    break;

                case AudioText:
                    var audioFormat = value.Split(':');
                    int.TryParse(audioFormat[0], out audioSampleRate);
                    int.TryParse(audioFormat[1], out audioBits);
                    int.TryParse(audioFormat[2], out audioChannels);
                    break;

                case XfadeText:
                    int.TryParse(value, out crossfade);
                    break;

                case StateText:
                    Enum.TryParse(value, true, out mpdState);
                    break;

                case ElapsedText:
                    elapsed = ParseTime(value);
                    break;

                case TimeText:
                    break;

                case DurationText:
                    duration = ParseTime(value);
                    break;

                case MixrampDbText:
                    double.TryParse(value, out mixrampDb);
                    break;

                case UpdatingDbText:
                    int.TryParse(value, out updatingDb);
                    break;

                default:
                    Debug.WriteLine($"Unprocessed status: {keyValuePair.Key} - {keyValuePair.Value}");
                    break;
                }
            }

            return(new MpdStatus(
                       volume,
                       repeat,
                       random,
                       consume,
                       single,
                       playlist,
                       playlistLength,
                       crossfade,
                       mpdState,
                       playlistSong,
                       playlistSongId,
                       playlistNextSong,
                       playlistNextSongId,
                       elapsed,
                       duration,
                       bitrate,
                       audioSampleRate,
                       audioBits,
                       audioChannels,
                       updatingDb,
                       error));
        }