Ejemplo n.º 1
0
        public CurrentState(RemotedWindowsMediaPlayer remotePlayer)
        {
            IWMPMedia    current_item = remotePlayer.getCurrentMediaItem();
            IWMPPlaylist playlist     = remotePlayer.getNowPlaying();
            int          index        = -1;

            if (playlist != null && playlist.count > 0)
            {
                for (int j = 0; j < playlist.count; j++)
                {
                    IWMPMedia item = playlist.get_Item(j);
                    if (item != null && item.get_isIdentical(current_item))
                    {
                        index = j;
                    }
                }
            }
            if (index >= 0)
            {
                current_track = new PlaylistTrack(index, current_item);
            }
            shuffle_mode = remotePlayer.isShuffleModeEnabled();
            play_state   = getTruncatedPlayState(remotePlayer.getPlayState());
            VolumeCmd volumeCmd = new VolumeCmd();

            volume   = volumeCmd.getVolume();
            is_muted = volumeCmd.isMuted();
        }
Ejemplo n.º 2
0
        void StartSendRequestThread(Object o)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;

            SocketAsyncEventArgs e = (SocketAsyncEventArgs)o;
            DataHolderToken token = (DataHolderToken)e.UserToken;

            string[] command = getCommandsFromArgs(e);
            string sCommand = command[0];
            string sParam = (command.Length == 2 ? command[1] : string.Empty);

            try
            {
                Thread http_thread = new Thread(new ParameterizedThreadStart(NewRequestThread));
                http_thread.SetApartmentState(ApartmentState.MTA);

                //Check if command for setting cache hour
                if (sCommand.Equals("music-clear-cache") && MusicCmd.check_cache_command(sParam) != -1)
                {
                    XmlNode cacheStartHourNode = getSettingsDoc().DocumentElement.SelectSingleNode("cacheStartHour");
                    if (cacheStartHourNode != null)
                    {
                        int cacheStartHour = MusicCmd.check_cache_command(sParam);
                        setCacheBuildTimer(cacheStartHour);

                        token.opResult = new OpResult();
                        token.opResult.StatusCode = OpStatusCode.Success;
                        token.opResult.StatusText = "Cache start hour set to " + cacheStartHour;
                    }
                    else
                    {
                        token.opResult = new OpResult();
                        token.opResult.StatusCode = OpStatusCode.BadRequest;
                        token.opResult.StatusText = "cacheStartHour node not found in settings.xml!";
                    }
                }
                else if (sCommand.Equals("music-list-playing") || sCommand.Equals("music-list-current") || sCommand.StartsWith("play") ||
                    sCommand.Equals("music-shuffle"))
                {
                    RemotedWindowsMediaPlayer remotePlayer = new RemotedWindowsMediaPlayer();
                    remotePlayer.CreateControl();

                    if (sCommand.Equals("music-list-playing"))
                    {
                        if (sParam != null && sParam.Length != 0)
                        {
                            string sIndex = sParam.Substring(sParam.IndexOf("index:") + "index:".Length);
                            if (remotePlayer.setNowPlaying(Int16.Parse(sIndex)))
                            {
                                token.opResult = new OpResult();
                                token.opResult.StatusCode = OpStatusCode.Success;
                                token.opResult.StatusText = "Current media set to index " + sIndex;
                            }
                            else
                            {
                                token.opResult = new OpResult();
                                token.opResult.StatusCode = OpStatusCode.BadRequest;
                                token.opResult.StatusText = "Current playback item not set";
                            }
                        }
                        else
                        {
                            token.nowPlaying = new NowPlayingList(remotePlayer.getNowPlaying());
                        }
                    }
                    else if (sCommand.StartsWith("play"))
                    {
                        //For playrate and playstate-get commands
                        token.opResult = m_remoteCommands.Execute(remotePlayer, sCommand, sParam);
                    }
                    else if (sCommand.Equals("music-shuffle"))
                    {
                        remotePlayer.setShuffleMode();
                        token.opResult = new OpResult();
                        token.opResult.StatusCode = OpStatusCode.Success;
                        token.opResult.StatusText = "Shuffle mode set";
                    }
                    else
                    {
                        //"music-list-current" command
                        token.currentMedia = new MediaItem(remotePlayer.getCurrentMediaItem());
                        MediaPlayState playState = new MediaPlayState(remotePlayer.getPlayState());
                        token.currentMedia.play_state = playState.getState();
                    }

                    if (remotePlayer != null)
                    {
                        remotePlayer.Dispose();
                    }
                }

                http_thread.Start(e);
            }
            catch (COMException)
            {
            }
        }