Skip to content

Commit

Permalink
[builtin] adds new builtin for seeking
Browse files Browse the repository at this point in the history
  • Loading branch information
xhaggi committed Mar 23, 2015
1 parent 5d10bfb commit d1346d3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions xbmc/interfaces/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "system.h"
#include "utils/AlarmClock.h"
#include "utils/Screenshot.h"
#include "utils/SeekHandler.h"
#include "Application.h"
#include "ApplicationMessenger.h"
#include "Autorun.h"
Expand Down Expand Up @@ -149,6 +150,7 @@ const BUILT_IN commands[] = {
{ "NotifyAll", true, "Notify all connected clients" },
{ "Extract", true, "Extracts the specified archive" },
{ "PlayMedia", true, "Play the specified media file (or playlist)" },
{ "Seek", true, "Performs a seek in seconds on the current playing media file" },
{ "ShowPicture", true, "Display a picture by file path" },
{ "SlideShow", true, "Run a slideshow from the specified directory" },
{ "RecursiveSlideShow", true, "Run a slideshow from the specified directory, including all subdirs" },
Expand Down Expand Up @@ -800,6 +802,16 @@ int CBuiltins::Execute(const std::string& execString)
}
}
}
else if (execute == "seek")
{
if (!params.size())
{
CLog::Log(LOGERROR, "Seek called with empty parameter");
return -3;
}
if (g_application.m_pPlayer->IsPlaying())
CSeekHandler::Get().SeekSeconds(atoi(params[0].c_str()));
}
else if (execute == "showpicture")
{
if (!params.size())
Expand Down
24 changes: 24 additions & 0 deletions xbmc/utils/SeekHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,30 @@ void CSeekHandler::Seek(bool forward, float amount, float duration /* = 0 */, bo
m_timer.StartZero();
}

void CSeekHandler::SeekSeconds(int seconds)
{
if (seconds == 0 || g_infoManager.GetTotalPlayTime() == 0)
return;

CSingleLock lock(m_critSection);

m_requireSeek = true;
m_seekDelay = 0;

g_infoManager.SetSeeking(true);
g_infoManager.SetSeekStepSize(seconds);

float percentPlayTime = static_cast<float>(g_infoManager.GetPlayTime()) / g_infoManager.GetTotalPlayTime() * 0.1f;
float percentPerSecond = 100.0f / static_cast<float>(g_infoManager.GetTotalPlayTime());

m_percent = percentPlayTime + percentPerSecond * seconds;

if (m_percent > 100.0f)
m_percent = 100.0f;
if (m_percent < 0.0f)
m_percent = 0.0f;
}

float CSeekHandler::GetPercent() const
{
return m_percent;
Expand Down
4 changes: 4 additions & 0 deletions xbmc/utils/SeekHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "interfaces/IActionListener.h"
#include "settings/Settings.h"
#include "settings/lib/ISettingCallback.h"
#include "threads/CriticalSection.h"
#include "utils/Stopwatch.h"

enum SeekType
Expand All @@ -43,6 +44,7 @@ class CSeekHandler : public ISettingCallback, public IActionListener
virtual bool OnAction(const CAction &action);

void Seek(bool forward, float amount, float duration = 0, bool analogSeek = false, SeekType type = SEEK_TYPE_VIDEO);
void SeekSeconds(int seconds);
void Process();
void Reset();

Expand All @@ -69,4 +71,6 @@ class CSeekHandler : public ISettingCallback, public IActionListener
std::map<SeekType, std::vector<int> > m_forwardSeekSteps;
std::map<SeekType, std::vector<int> > m_backwardSeekSteps;
CStopWatch m_timer;

CCriticalSection m_critSection;
};

0 comments on commit d1346d3

Please sign in to comment.