コード例 #1
0
        private bool HandleServiceMessage(string topic, ByteQueue data)
        {
            switch (topic)
            {
            case nameof(Service.SourcePlaylists):
                HandleSourcePlaylistsTopic(data);
                break;

            case nameof(Service.Playlists):
                HandlePlaylistsTopic(data);
                break;

            case nameof(Service.AudioData):
                Service.AudioData = data;
                break;

            case nameof(Service.CurrentPlaylist):
                HandleCurrentPlaylistTopic(data);
                break;

            case nameof(Service.PlayState):
                Service.PlayState = (PlaybackState)data.DequeueInt();
                break;

            case nameof(Service.Volume):
                Service.Volume = data.DequeueFloat();
                break;

            case nameof(Service.IsSearchShuffle):
                Service.IsSearchShuffle = data.DequeueBool();
                break;

            case nameof(Service.SearchKey):
                Service.SearchKey = data.DequeueString();
                break;

            case cmdString:
                IAudioService service;
                string        cmd = Encoding.UTF8.GetString(data);

                switch (cmd.ToLower())
                {
                case "play":
                    Service.PlayState = PlaybackState.Playing;
                    break;

                case "pause":
                    Service.PlayState = PlaybackState.Paused;
                    break;

                case "toggle":
                    Service.PlayState = Service.PlayState != PlaybackState.Playing
                                ? PlaybackState.Playing
                                : PlaybackState.Paused;
                    break;

                case "next":
                    service = Service as IAudioService;
                    service?.SetNextSong();
                    break;

                case "previous":
                    service = Service as IAudioService;
                    service?.SetPreviousSong();
                    break;

                default:
                    return(false);
                }
                break;

            default:
                return(false);
            }

            return(true);
        }