示例#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();
        }
示例#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)
            {
            }
        }
示例#3
0
 public OpResult Execute(String command, string param, ServerSettings settings, RemotedWindowsMediaPlayer remotePlayer)
 {
     command = command.ToLower();
     if (m_commands.ContainsKey(command))
     {
         try
         {
             if (command.Equals("music-list-stats"))
             {
                 return(ExecuteLibraryStats(settings));
             }
             else if (m_commands[command] is MusicCmd)
             {
                 //Make sure cache is not being modified before executing any of the music-* commands
                 if (cacheLock.TryEnterReadLock(10))
                 {
                     try
                     {
                         return(((ICommand)m_commands[command]).Execute(param));
                     }
                     finally
                     {
                         cacheLock.ExitReadLock();
                     }
                 }
                 else
                 {
                     return(getSettings(settings, true));
                 }
             }
             else if (m_commands[command] is IExperienceCommand || m_commands[command] is IWmpCommand)
             {
                 //Only allow one thread at a time to access remoted player
                 waitHandle.WaitOne();
                 try
                 {
                     if (m_commands[command] is IWmpCommand)
                     {
                         return(((IWmpCommand)m_commands[command]).Execute(remotePlayer, param));
                     }
                     else
                     {
                         return(((IExperienceCommand)m_commands[command]).ExecuteMediaExperience(param));
                     }
                 }
                 finally
                 {
                     waitHandle.Set();
                 }
             }
             else
             {
                 return(((ICommand)m_commands[command]).Execute(param));
             }
         }
         catch (Exception ex)
         {
             OpResult opResult = new OpResult();
             opResult.StatusCode = OpStatusCode.Exception;
             opResult.StatusText = ex.Message;
             opResult.AppendFormat(ex.Message);
             return(opResult);
         }
     }
     else
     {
         return(new OpResult(OpStatusCode.BadRequest));
     }
 }
示例#4
0
 public OpResult Execute(RemotedWindowsMediaPlayer remotePlayer, String command, string param)
 {
     return(Execute(command, param, null, remotePlayer));
 }
示例#5
0
 public OpResult Execute(RemotedWindowsMediaPlayer remotePlayer, String command, string param)
 {
     return ((WmpICommand)m_commands[command]).Execute(remotePlayer, param);
 }
示例#6
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);

            Thread http_thread = new Thread(new ParameterizedThreadStart(NewRequestThread));

            http_thread.IsBackground = true;
            http_thread.SetApartmentState(ApartmentState.MTA);

            if (sCommand.Equals("music-list-playing") || sCommand.Equals("music-list-current") || sCommand.StartsWith("play") || sCommand.Equals("music-shuffle"))
            {
                RemotedWindowsMediaPlayer remotedPlayer = null;
                try
                {
                    //Only allow one thread at a time to access remoted player
                    waitHandle.WaitOne();

                    remotedPlayer = new RemotedWindowsMediaPlayer();
                    remotedPlayer.CreateControl();

                    token.opResult = new OpResult();
                    if (sCommand.Equals("music-list-playing"))
                    {
                        if (sParam != null && sParam.Length != 0)
                        {
                            string sIndex = sParam.Substring(sParam.IndexOf("index:") + "index:".Length);
                            if (remotedPlayer.setNowPlaying(Int16.Parse(sIndex)))
                            {
                                token.opResult.StatusCode = OpStatusCode.Success;
                                token.opResult.StatusText = "Current media set to index " + sIndex;
                            }
                            else
                            {
                                token.opResult.StatusCode = OpStatusCode.BadRequest;
                                token.opResult.StatusText = "Current playback item not set";
                            }
                        }
                        else
                        {
                            token.opResult.StatusCode = OpStatusCode.Success;
                            NowPlaying nowPlaying = new NowPlaying(remotedPlayer);
                            token.opResult.ContentObject = nowPlaying;
                        }
                    }
                    else if (sCommand.StartsWith("play"))
                    {
                        //For playrate and playstate-get commands
                        token.opResult = remoteCommands.Execute(remotedPlayer, sCommand, sParam);
                    }
                    else if (sCommand.Equals("music-shuffle"))
                    {
                        remotedPlayer.setShuffleMode();
                        token.opResult.StatusCode = OpStatusCode.Success;
                        token.opResult.StatusText = "Shuffle mode set to true";
                    }
                    else
                    {
                        //"music-list-current" command
                        token.opResult.StatusCode = OpStatusCode.Success;
                        CurrentState state = new CurrentState(remotedPlayer);
                        token.opResult.ContentObject = state;
                    }
                }
                catch (Exception c)
                {
                    logger.Write("Exception in StartSendRequestThread: " + c.Message);
                    token.opResult.StatusCode = OpStatusCode.Exception;
                    token.opResult.StatusText = c.Message;
                }
                finally
                {
                    if (remotedPlayer != null)
                    {
                        remotedPlayer.Dispose();
                    }
                    waitHandle.Set();
                }
            }

            http_thread.Start(e);
        }