예제 #1
0
/*! \brief Start a playlist from a given offset.
 *  \param params The parameters.
 *  \details params[0] = Position in playlist or playlist type.
 *           params[1] = Position in playlist if params[0] is playlist type (optional).
 */
static int PlayOffset(const std::vector<std::string>& params)
{
  // playlist.playoffset(offset)
  // playlist.playoffset(music|video,offset)
  std::string strPos = params[0];
  std::string paramlow(params[0]);
  StringUtils::ToLower(paramlow);
  if (params.size() > 1)
  {
    // ignore any other parameters if present
    std::string strPlaylist = params[0];
    strPos = params[1];

    int iPlaylist = PLAYLIST_NONE;
    if (paramlow == "music")
      iPlaylist = PLAYLIST_MUSIC;
    else if (paramlow == "video")
      iPlaylist = PLAYLIST_VIDEO;

    // unknown playlist
    if (iPlaylist == PLAYLIST_NONE)
    {
      CLog::Log(LOGERROR,"Playlist.PlayOffset called with unknown playlist: %s", strPlaylist.c_str());
      return false;
    }

    // user wants to play the 'other' playlist
    if (iPlaylist != CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist())
    {
      g_application.StopPlaying();
      CServiceBroker::GetPlaylistPlayer().Reset();
      CServiceBroker::GetPlaylistPlayer().SetCurrentPlaylist(iPlaylist);
    }
  }
  // play the desired offset
  int pos = atol(strPos.c_str());
  // playlist is already playing
  if (g_application.GetAppPlayer().IsPlaying())
    CServiceBroker::GetPlaylistPlayer().PlayNext(pos);
  // we start playing the 'other' playlist so we need to use play to initialize the player state
  else
    CServiceBroker::GetPlaylistPlayer().Play(pos, "");

  return 0;
}
예제 #2
0
/*! \brief Control player.
 *  \param params The parameters
 *  \details params[0] = Control to execute.
 *           params[1] = "notify" to notify user (optional, certain controls).
 */
static int PlayerControl(const std::vector<std::string>& params)
{
  g_application.ResetScreenSaver();
  g_application.WakeUpScreenSaverAndDPMS();

  std::string paramlow(params[0]);
  StringUtils::ToLower(paramlow);

  if (paramlow ==  "play")
  { // play/pause
    // either resume playing, or pause
    if (g_application.GetAppPlayer().IsPlaying())
    {
      if (g_application.GetAppPlayer().GetPlaySpeed() != 1)
        g_application.GetAppPlayer().SetPlaySpeed(1);
      else
        g_application.GetAppPlayer().Pause();
    }
  }
  else if (paramlow == "stop")
  {
    g_application.StopPlaying();
  }
  else if (StringUtils::StartsWithNoCase(params[0], "frameadvance"))
  {
    std::string strFrames;
    if (params[0].size() == 12)
      CLog::Log(LOGERROR, "PlayerControl(frameadvance(n)) called with no argument");
    else if (params[0].size() < 15) // arg must be at least "(N)"
      CLog::Log(LOGERROR, "PlayerControl(frameadvance(n)) called with invalid argument: \"%s\"", params[0].substr(13).c_str());
    else

    strFrames = params[0].substr(13);
    StringUtils::TrimRight(strFrames, ")");
    float frames = (float) atof(strFrames.c_str());
    g_application.GetAppPlayer().FrameAdvance(frames);
  }
  else if (paramlow =="rewind" || paramlow == "forward")
  {
    if (g_application.GetAppPlayer().IsPlaying() && !g_application.GetAppPlayer().IsPaused())
    {
      float playSpeed = g_application.GetAppPlayer().GetPlaySpeed();

      if (paramlow == "rewind" && playSpeed == 1) // Enables Rewinding
        playSpeed *= -2;
      else if (paramlow == "rewind" && playSpeed > 1) //goes down a notch if you're FFing
        playSpeed /= 2;
      else if (paramlow == "forward" && playSpeed < 1) //goes up a notch if you're RWing
      {
        playSpeed /= 2;
        if (playSpeed == -1)
          playSpeed = 1;
      }
      else
        playSpeed *= 2;

      if (playSpeed > 32 || playSpeed < -32)
        playSpeed = 1;

      g_application.GetAppPlayer().SetPlaySpeed(playSpeed);
    }
  }
  else if (paramlow =="tempoup" || paramlow == "tempodown")
  {
    if (g_application.GetAppPlayer().SupportsTempo() &&
        g_application.GetAppPlayer().IsPlaying() && !g_application.GetAppPlayer().IsPaused())
    {
      float playTempo = g_application.GetAppPlayer().GetPlayTempo();
      if (paramlow == "tempodown")
          playTempo -= 0.1f;
      else if (paramlow == "tempoup")
          playTempo += 0.1f;

      g_application.GetAppPlayer().SetTempo(playTempo);
    }
  }
  else if (paramlow == "next")
  {
    g_application.OnAction(CAction(ACTION_NEXT_ITEM));
  }
  else if (paramlow == "previous")
  {
    g_application.OnAction(CAction(ACTION_PREV_ITEM));
  }
  else if (paramlow == "bigskipbackward")
  {
    if (g_application.GetAppPlayer().IsPlaying())
      g_application.GetAppPlayer().Seek(false, true);
  }
  else if (paramlow == "bigskipforward")
  {
    if (g_application.GetAppPlayer().IsPlaying())
      g_application.GetAppPlayer().Seek(true, true);
  }
  else if (paramlow == "smallskipbackward")
  {
    if (g_application.GetAppPlayer().IsPlaying())
      g_application.GetAppPlayer().Seek(false, false);
  }
  else if (paramlow == "smallskipforward")
  {
    if (g_application.GetAppPlayer().IsPlaying())
      g_application.GetAppPlayer().Seek(true, false);
  }
  else if (StringUtils::StartsWithNoCase(params[0], "seekpercentage"))
  {
    std::string offset;
    if (params[0].size() == 14)
      CLog::Log(LOGERROR,"PlayerControl(seekpercentage(n)) called with no argument");
    else if (params[0].size() < 17) // arg must be at least "(N)"
      CLog::Log(LOGERROR,"PlayerControl(seekpercentage(n)) called with invalid argument: \"%s\"", params[0].substr(14).c_str());
    else
    {
      // Don't bother checking the argument: an invalid arg will do seek(0)
      offset = params[0].substr(15);
      StringUtils::TrimRight(offset, ")");
      float offsetpercent = (float) atof(offset.c_str());
      if (offsetpercent < 0 || offsetpercent > 100)
        CLog::Log(LOGERROR,"PlayerControl(seekpercentage(n)) argument, %f, must be 0-100", offsetpercent);
      else if (g_application.GetAppPlayer().IsPlaying())
        g_application.SeekPercentage(offsetpercent);
    }
  }
  else if (paramlow == "showvideomenu")
  {
    if( g_application.GetAppPlayer().IsPlaying() )
      g_application.GetAppPlayer().OnAction(CAction(ACTION_SHOW_VIDEOMENU));
  }
  else if (StringUtils::StartsWithNoCase(params[0], "partymode"))
  {
    std::string strXspPath;
    //empty param=music, "music"=music, "video"=video, else xsp path
    PartyModeContext context = PARTYMODECONTEXT_MUSIC;
    if (params[0].size() > 9)
    {
      if (params[0].size() == 16 && StringUtils::EndsWithNoCase(params[0], "video)"))
        context = PARTYMODECONTEXT_VIDEO;
      else if (params[0].size() != 16 || !StringUtils::EndsWithNoCase(params[0], "music)"))
      {
        strXspPath = params[0].substr(10);
        StringUtils::TrimRight(strXspPath, ")");
        context = PARTYMODECONTEXT_UNKNOWN;
      }
    }
    if (g_partyModeManager.IsEnabled())
      g_partyModeManager.Disable();
    else
      g_partyModeManager.Enable(context, strXspPath);
  }
  else if (paramlow == "random" || paramlow == "randomoff" || paramlow == "randomon")
  {
    // get current playlist
    int iPlaylist = CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist();

    // reverse the current setting
    bool shuffled = CServiceBroker::GetPlaylistPlayer().IsShuffled(iPlaylist);
    if ((shuffled && paramlow == "randomon") || (!shuffled && paramlow == "randomoff"))
      return 0;

    // check to see if we should notify the user
    bool notify = (params.size() == 2 && StringUtils::EqualsNoCase(params[1], "notify"));
    CServiceBroker::GetPlaylistPlayer().SetShuffle(iPlaylist, !shuffled, notify);

    // save settings for now playing windows
    switch (iPlaylist)
    {
      case PLAYLIST_MUSIC:
        CMediaSettings::GetInstance().SetMusicPlaylistShuffled(CServiceBroker::GetPlaylistPlayer().IsShuffled(iPlaylist));
        CServiceBroker::GetSettings().Save();
        break;
      case PLAYLIST_VIDEO:
        CMediaSettings::GetInstance().SetVideoPlaylistShuffled(CServiceBroker::GetPlaylistPlayer().IsShuffled(iPlaylist));
        CServiceBroker::GetSettings().Save();
      default:
        break;
    }

    // send message
    CGUIMessage msg(GUI_MSG_PLAYLISTPLAYER_RANDOM, 0, 0, iPlaylist, CServiceBroker::GetPlaylistPlayer().IsShuffled(iPlaylist));
    CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg);
  }
  else if (StringUtils::StartsWithNoCase(params[0], "repeat"))
  {
    // get current playlist
    int iPlaylist = CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist();
    PLAYLIST::REPEAT_STATE previous_state = CServiceBroker::GetPlaylistPlayer().GetRepeat(iPlaylist);

    std::string paramlow(params[0]);
    StringUtils::ToLower(paramlow);

    PLAYLIST::REPEAT_STATE state;
    if (paramlow == "repeatall")
      state = PLAYLIST::REPEAT_ALL;
    else if (paramlow == "repeatone")
      state = PLAYLIST::REPEAT_ONE;
    else if (paramlow == "repeatoff")
      state = PLAYLIST::REPEAT_NONE;
    else if (previous_state == PLAYLIST::REPEAT_NONE)
      state = PLAYLIST::REPEAT_ALL;
    else if (previous_state == PLAYLIST::REPEAT_ALL)
      state = PLAYLIST::REPEAT_ONE;
    else
      state = PLAYLIST::REPEAT_NONE;

    if (state == previous_state)
      return 0;

    // check to see if we should notify the user
    bool notify = (params.size() == 2 && StringUtils::EqualsNoCase(params[1], "notify"));
    CServiceBroker::GetPlaylistPlayer().SetRepeat(iPlaylist, state, notify);

    // save settings for now playing windows
    switch (iPlaylist)
    {
      case PLAYLIST_MUSIC:
        CMediaSettings::GetInstance().SetMusicPlaylistRepeat(state == PLAYLIST::REPEAT_ALL);
        CServiceBroker::GetSettings().Save();
        break;
      case PLAYLIST_VIDEO:
        CMediaSettings::GetInstance().SetVideoPlaylistRepeat(state == PLAYLIST::REPEAT_ALL);
        CServiceBroker::GetSettings().Save();
    }

    // send messages so now playing window can get updated
    CGUIMessage msg(GUI_MSG_PLAYLISTPLAYER_REPEAT, 0, 0, iPlaylist, (int)state);
    CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg);
  }
  else if (StringUtils::StartsWithNoCase(params[0], "resumelivetv"))
  {
    CFileItem& fileItem(g_application.CurrentFileItem());
    PVR::CPVRChannelPtr channel = fileItem.HasPVRRecordingInfoTag() ? fileItem.GetPVRRecordingInfoTag()->Channel() : PVR::CPVRChannelPtr();

    if (channel)
    {
      CFileItem playItem(channel);
      if (!g_application.PlayMedia(playItem, "", channel->IsRadio() ? PLAYLIST_MUSIC : PLAYLIST_VIDEO))
      {
        CLog::Log(LOGERROR, "ResumeLiveTv could not play channel: %s", channel->ChannelName().c_str());
        return false;
      }
    }
  }
  else if (paramlow == "reset")
  {
    g_application.OnAction(CAction(ACTION_PLAYER_RESET));
  }

  return 0;
}
예제 #3
0
/*! \brief Control player.
 *  \param params The parameters
 *  \details params[0] = Control to execute.
 *           params[1] = "notify" to notify user (optional, certain controls).
 */
static int PlayerControl(const std::vector<std::string>& params)
{
  g_application.ResetScreenSaver();
  g_application.WakeUpScreenSaverAndDPMS();

  std::string paramlow(params[0]);
  StringUtils::ToLower(paramlow);

  if (paramlow ==  "play")
  { // play/pause
    // either resume playing, or pause
    if (g_application.m_pPlayer->IsPlaying())
    {
      if (g_application.m_pPlayer->GetPlaySpeed() != 1)
        g_application.m_pPlayer->SetPlaySpeed(1, g_application.IsMutedInternal());
      else
        g_application.m_pPlayer->Pause();
    }
  }
  else if (paramlow == "stop")
  {
    g_application.StopPlaying();
  }
  else if (paramlow =="rewind" || paramlow == "forward")
  {
    if (g_application.m_pPlayer->IsPlaying() && !g_application.m_pPlayer->IsPaused())
    {
      int iPlaySpeed = g_application.m_pPlayer->GetPlaySpeed();
      if (paramlow == "rewind" && iPlaySpeed == 1) // Enables Rewinding
        iPlaySpeed *= -2;
      else if (paramlow ==  "rewind" && iPlaySpeed > 1) //goes down a notch if you're FFing
        iPlaySpeed /= 2;
      else if (paramlow == "forward" && iPlaySpeed < 1) //goes up a notch if you're RWing
      {
        iPlaySpeed /= 2;
        if (iPlaySpeed == -1) iPlaySpeed = 1;
      }
      else
        iPlaySpeed *= 2;

      if (iPlaySpeed > 32 || iPlaySpeed < -32)
        iPlaySpeed = 1;

      g_application.m_pPlayer->SetPlaySpeed(iPlaySpeed, g_application.IsMutedInternal());
    }
  }
  else if (paramlow == "next")
  {
    g_application.OnAction(CAction(ACTION_NEXT_ITEM));
  }
  else if (paramlow == "previous")
  {
    g_application.OnAction(CAction(ACTION_PREV_ITEM));
  }
  else if (paramlow == "bigskipbackward")
  {
    if (g_application.m_pPlayer->IsPlaying())
      g_application.m_pPlayer->Seek(false, true);
  }
  else if (paramlow == "bigskipforward")
  {
    if (g_application.m_pPlayer->IsPlaying())
      g_application.m_pPlayer->Seek(true, true);
  }
  else if (paramlow == "smallskipbackward")
  {
    if (g_application.m_pPlayer->IsPlaying())
      g_application.m_pPlayer->Seek(false, false);
  }
  else if (paramlow == "smallskipforward")
  {
    if (g_application.m_pPlayer->IsPlaying())
      g_application.m_pPlayer->Seek(true, false);
  }
  else if (StringUtils::StartsWithNoCase(params[0], "seekpercentage"))
  {
    std::string offset;
    if (params[0].size() == 14)
      CLog::Log(LOGERROR,"PlayerControl(seekpercentage(n)) called with no argument");
    else if (params[0].size() < 17) // arg must be at least "(N)"
      CLog::Log(LOGERROR,"PlayerControl(seekpercentage(n)) called with invalid argument: \"%s\"", params[0].substr(14).c_str());
    else
    {
      // Don't bother checking the argument: an invalid arg will do seek(0)
      offset = params[0].substr(15);
      StringUtils::TrimRight(offset, ")");
      float offsetpercent = (float) atof(offset.c_str());
      if (offsetpercent < 0 || offsetpercent > 100)
        CLog::Log(LOGERROR,"PlayerControl(seekpercentage(n)) argument, %f, must be 0-100", offsetpercent);
      else if (g_application.m_pPlayer->IsPlaying())
        g_application.SeekPercentage(offsetpercent);
    }
  }
  else if (paramlow == "showvideomenu")
  {
    if( g_application.m_pPlayer->IsPlaying() )
      g_application.m_pPlayer->OnAction(CAction(ACTION_SHOW_VIDEOMENU));
  }
  else if (paramlow == "record")
  {
    if( g_application.m_pPlayer->IsPlaying() && g_application.m_pPlayer->CanRecord())
      g_application.m_pPlayer->Record(!g_application.m_pPlayer->IsRecording());
  }
  else if (StringUtils::StartsWithNoCase(params[0], "partymode"))
  {
    std::string strXspPath;
    //empty param=music, "music"=music, "video"=video, else xsp path
    PartyModeContext context = PARTYMODECONTEXT_MUSIC;
    if (params[0].size() > 9)
    {
      if (params[0].size() == 16 && StringUtils::EndsWithNoCase(params[0], "video)"))
        context = PARTYMODECONTEXT_VIDEO;
      else if (params[0].size() != 16 || !StringUtils::EndsWithNoCase(params[0], "music)"))
      {
        strXspPath = params[0].substr(10);
        StringUtils::TrimRight(strXspPath, ")");
        context = PARTYMODECONTEXT_UNKNOWN;
      }
    }
    if (g_partyModeManager.IsEnabled())
      g_partyModeManager.Disable();
    else
      g_partyModeManager.Enable(context, strXspPath);
  }
  else if (paramlow == "random" || paramlow == "randomoff" || paramlow == "randomon")
  {
    // get current playlist
    int iPlaylist = g_playlistPlayer.GetCurrentPlaylist();

    // reverse the current setting
    bool shuffled = g_playlistPlayer.IsShuffled(iPlaylist);
    if ((shuffled && paramlow == "randomon") || (!shuffled && paramlow == "randomoff"))
      return 0;

    // check to see if we should notify the user
    bool notify = (params.size() == 2 && StringUtils::EqualsNoCase(params[1], "notify"));
    g_playlistPlayer.SetShuffle(iPlaylist, !shuffled, notify);

    // save settings for now playing windows
    switch (iPlaylist)
    {
      case PLAYLIST_MUSIC:
        CMediaSettings::Get().SetMusicPlaylistShuffled(g_playlistPlayer.IsShuffled(iPlaylist));
        CSettings::Get().Save();
        break;
      case PLAYLIST_VIDEO:
        CMediaSettings::Get().SetVideoPlaylistShuffled(g_playlistPlayer.IsShuffled(iPlaylist));
        CSettings::Get().Save();
    }

    // send message
    CGUIMessage msg(GUI_MSG_PLAYLISTPLAYER_RANDOM, 0, 0, iPlaylist, g_playlistPlayer.IsShuffled(iPlaylist));
    g_windowManager.SendThreadMessage(msg);
  }

  return 0;
}