コード例 #1
0
    private static void OnClick(object sender, RemoteEventArgs e)
    {
      Log.Write("MPTray: OnClick");
      if (e.Button != RemoteButton.Start)
      {
        return;
      }

      Process[] processes = Process.GetProcessesByName("mediaportal");

      if (processes.Length != 0)
      {
        if (processes.Length > 1)
        {
          Log.Write("MPTray: More than one window named \"MediaPortal\" has been found!");
          foreach (Process procName in processes)
          {
            Log.Write("MPTray: {0} (Started: {1}, ID: {2})", procName.ProcessName,
                      procName.StartTime.ToShortTimeString(), procName.Id);
          }
        }
        Log.Write("MPTray: MediaPortal is already running - switching focus.");
        SwitchFocus();
      }
      else
      {
        try
        {
          Uri uri = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase);

          Process process = new Process
                              {
                                StartInfo =
                                  {
                                    FileName = "mediaportal.exe",
                                    WorkingDirectory = Path.GetDirectoryName(uri.LocalPath),
                                    UseShellExecute = true
                                  }
                              };

          Log.Write("MPTray: starting MediaPortal");
          process.Start();
        }
        catch (Exception ex)
        {
          Log.Write("MPTray: Error starting MediaPortal {0}", ex.Message);
        }
      }
    }
コード例 #2
0
    /// <summary>
    /// Evaluate button press from remote
    /// </summary>
    /// <param name="button">Remote Button</param>
    private void OnRemoteClick(object sender, RemoteEventArgs e)
      //RemoteButton button)
    {
      RemoteButton button = e.Button;
      if (logVerbose)
      {
        Log.Info("MCE: Incoming button command: {0}", button);
      }

      // Set LastHidRequest, otherwise the HID handler (if enabled) would react on some remote buttons (double execution of command)
      switch (button)
      {
        case RemoteButton.Record:
          InputDevices.LastHidRequest = AppCommands.MediaRecord;
          break;
        case RemoteButton.Stop:
          InputDevices.LastHidRequest = AppCommands.MediaStop;
          break;
        case RemoteButton.Pause:
          InputDevices.LastHidRequest = AppCommands.MediaPause;
          break;
        case RemoteButton.Rewind:
          InputDevices.LastHidRequest = AppCommands.MediaRewind;
          break;
        case RemoteButton.Play:
          InputDevices.LastHidRequest = AppCommands.MediaPlay;
          break;
        case RemoteButton.Forward:
          InputDevices.LastHidRequest = AppCommands.MediaFastForward;
          break;
        case RemoteButton.Replay:
          InputDevices.LastHidRequest = AppCommands.MediaPreviousTrack;
          break;
        case RemoteButton.Skip:
          InputDevices.LastHidRequest = AppCommands.MediaNextTrack;
          break;
        case RemoteButton.Back:
          InputDevices.LastHidRequest = AppCommands.BrowserBackward;
          break;
        case RemoteButton.ChannelUp:
          return; // Don't handle this command, benefit from OS' repeat handling instead
        case RemoteButton.ChannelDown:
          return; // Don't handle this command, benefit from OS' repeat handling instead
        case RemoteButton.Mute:
          InputDevices.LastHidRequest = AppCommands.VolumeMute;
          break;
        case RemoteButton.VolumeUp:
          return; // Don't handle this command, benefit from OS' repeat handling instead
        case RemoteButton.VolumeDown:
          return; // Don't handle this command, benefit from OS' repeat handling instead
      }

      // Get & execute Mapping
      if (_inputHandler.MapAction((int)button))
      {
        if (logVerbose)
        {
          Log.Info("MCE: Command \"{0}\" mapped", button);
        }
      }
      else if (logVerbose)
      {
        Log.Info("MCE: Command \"{0}\" not mapped", button);
      }
    }
コード例 #3
0
ファイル: Program.cs プロジェクト: splatterpop/MediaPortal-1
    private static void OnClick(object sender, RemoteEventArgs e)
    {
      Log.Write("MPTray: OnClick");

        switch (e.Button)
        {
            case RemoteButton.Start:
                #region start

                Process[] processes = Process.GetProcessesByName("mediaportal");

                    if (processes.Length != 0)
                    {
                        if (processes.Length > 1)
                        {
                            Log.Write("MPTray: More than one process named \"MediaPortal\" has been found!");
                            foreach (Process procName in processes)
                            {
                                Log.Write("MPTray: {0} (Started: {1}, ID: {2})", procName.ProcessName, procName.StartTime.ToShortTimeString(), procName.Id);
                            }
                        }
                        Log.Write("MPTray: MediaPortal is already running - switching focus.");
                        SwitchFocus();
                    }
                    else
                    {
                        try
                        {
                            Uri uri = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase);

                            Process process = new Process
                                                {
                                                    StartInfo =
                                                      {
                                                          FileName = "mediaportal.exe",
                                                          WorkingDirectory = Path.GetDirectoryName(uri.LocalPath),
                                                          UseShellExecute = true
                                                      }
                                                };

                            Log.Write("MPTray: starting MediaPortal");
                            process.Start();

                            using (EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.ManualReset, "MediaPortalHandleCreated"))
                            {
                                if (handle.SafeWaitHandle.IsInvalid)
                                {
                                    return;
                                }

                                SwitchFocus();

                                handle.Set();
                                handle.Close();
                            }

                        }
                        catch (Exception ex)
                        {
                            Log.Write("MPTray: Error starting MediaPortal {0}", ex.Message);
                        }
                    }
                    break; // case RemoteButton.Start
            #endregion
            case RemoteButton.Power1:
            case RemoteButton.Power2:
            case RemoteButton.PowerTV:
            #region Power
                    
                    break; // case Remotebutton.Powerxxx
            #endregion
        } // switch
    }