Permalink
Browse files

Move the seek handling to the app. Fixes problems where analog seekin…

…g didn't respond while the seekbar wasn't allowed on screen. Fixes #11712
  • Loading branch information...
1 parent 124b538 commit c1398f47c82d3371ba9b4471bd1266d4078ad9a4 Jonathan Marshall committed Jul 8, 2012
View
@@ -104,6 +104,7 @@
#include "settings/AdvancedSettings.h"
#include "guilib/LocalizeStrings.h"
#include "utils/CPUInfo.h"
+#include "utils/SeekHandler.h"
#include "input/KeyboardStat.h"
#include "input/XBMC_vkeys.h"
@@ -375,6 +376,7 @@ CApplication::CApplication(void)
, m_progressTrackingItem(new CFileItem)
, m_videoInfoScanner(new CVideoInfoScanner)
, m_musicInfoScanner(new CMusicInfoScanner)
+ , m_seekHandler(new CSeekHandler)
{
TiXmlBase::SetCondenseWhiteSpace(false);
m_iPlaySpeed = 1;
@@ -445,6 +447,7 @@ CApplication::~CApplication(void)
#endif
delete m_dpms;
+ delete m_seekHandler;
delete m_pInertialScrollingHandler;
}
@@ -2712,9 +2715,7 @@ bool CApplication::OnAction(const CAction &action)
if (IsPlaying() && action.GetAmount() && (action.GetID() == ACTION_ANALOG_SEEK_FORWARD || action.GetID() == ACTION_ANALOG_SEEK_BACK))
{
if (!m_pPlayer->CanSeek()) return false;
- CGUIWindow *seekBar = g_windowManager.GetWindow(WINDOW_DIALOG_SEEK_BAR);
- if (seekBar)
- seekBar->OnAction(action);
+ m_seekHandler->Seek(action.GetID() == ACTION_ANALOG_SEEK_FORWARD, action.GetAmount(), action.GetRepeat());
return true;
}
if (action.GetID() == ACTION_GUIPROFILE_BEGIN)
@@ -2807,7 +2808,10 @@ void CApplication::FrameMove(bool processEvents, bool processGUI)
ProcessEventServer(frameTime);
ProcessPeripherals(frameTime);
if (processGUI)
+ {
m_pInertialScrollingHandler->ProcessInertialScroll(frameTime);
+ m_seekHandler->Process();
+ }
}
if (processGUI)
{
@@ -4721,6 +4725,9 @@ bool CApplication::OnMessage(CGUIMessage& message)
#ifdef TARGET_DARWIN
DarwinSetScheduling(message.GetMessage());
#endif
+ // reset the seek handler
+ m_seekHandler->Reset();
+
// Update our infoManager with the new details etc.
if (m_nextPlaylistItem >= 0)
{ // we've started a previously queued item
View
@@ -62,6 +62,7 @@ namespace MEDIA_DETECT
#include "windowing/XBMC_events.h"
#include "threads/Thread.h"
+class CSeekHandler;
class CKaraokeLyricsManager;
class CInertialScrollingHandler;
class CApplicationMessenger;
@@ -337,6 +338,12 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
bool ToggleDPMS(bool manual);
float GetDimScreenSaverLevel() const;
+
+ /*! \brief Retrieve the applications seek handler.
+ \return a constant pointer to the seek handler.
+ \sa CSeekHandler
+ */
+ const CSeekHandler *GetSeekHandler() const { return m_seekHandler; };
protected:
bool LoadSkin(const CStdString& skinID);
void LoadSkin(const boost::shared_ptr<ADDON::CSkinInfo>& skin);
@@ -436,6 +443,7 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
bool InitDirectoriesWin32();
void CreateUserDirs();
+ CSeekHandler *m_seekHandler;
CInertialScrollingHandler *m_pInertialScrollingHandler;
CApplicationMessenger m_applicationMessenger;
#if defined(HAS_LINUX_NETWORK)
@@ -20,7 +20,6 @@
*/
#include "system.h"
-#include "dialogs/GUIDialogSeekBar.h"
#include "windows/GUIMediaWindow.h"
#include "dialogs/GUIDialogFileBrowser.h"
#include "settings/GUIDialogContentSettings.h"
@@ -58,6 +57,7 @@
#include "utils/CPUInfo.h"
#include "utils/StringUtils.h"
#include "utils/MathUtils.h"
+#include "utils/SeekHandler.h"
// stuff for current song
#include "music/tags/MusicInfoTagLoaderFactory.h"
@@ -1731,11 +1731,8 @@ bool CGUIInfoManager::GetInt(int &value, int info, int contextWindow, const CGUI
value = (int)(g_application.GetCachePercentage());
break;
case PLAYER_SEEKBAR:
- {
- CGUIDialogSeekBar *seekBar = (CGUIDialogSeekBar*)g_windowManager.GetWindow(WINDOW_DIALOG_SEEK_BAR);
- value = seekBar ? (int)seekBar->GetPercentage() : 0;
- break;
- }
+ value = (int)g_application.GetSeekHandler()->GetPercent();
+ break;
case PLAYER_CACHELEVEL:
value = (int)(g_application.m_pPlayer->GetCacheLevel());
break;
@@ -2128,7 +2125,7 @@ bool CGUIInfoManager::GetBool(int condition1, int contextWindow, const CGUIListI
break;
case PLAYER_SEEKBAR:
{
- CGUIDialogSeekBar *seekBar = (CGUIDialogSeekBar*)g_windowManager.GetWindow(WINDOW_DIALOG_SEEK_BAR);
+ CGUIDialog *seekBar = (CGUIDialog*)g_windowManager.GetWindow(WINDOW_DIALOG_SEEK_BAR);
bReturn = seekBar ? seekBar->IsDialogRunning() : false;
}
break;
@@ -2736,12 +2733,7 @@ CStdString CGUIInfoManager::GetMultiInfoLabel(const GUIInfo &info, int contextWi
}
else if (info.m_info == PLAYER_SEEKTIME)
{
- TIME_FORMAT format = (TIME_FORMAT)info.GetData1();
- if (format == TIME_FORMAT_GUESS && GetTotalPlayTime() >= 3600)
- format = TIME_FORMAT_HH_MM_SS;
- CGUIDialogSeekBar *seekBar = (CGUIDialogSeekBar*)g_windowManager.GetWindow(WINDOW_DIALOG_SEEK_BAR);
- if (seekBar)
- return seekBar->GetSeekTimeLabel(format);
+ return GetCurrentSeekTime((TIME_FORMAT)info.GetData1());
}
else if (info.m_info == PLAYER_SEEKOFFSET)
{
@@ -3493,6 +3485,14 @@ CStdString CGUIInfoManager::GetCurrentPlayTime(TIME_FORMAT format) const
return "";
}
+CStdString CGUIInfoManager::GetCurrentSeekTime(TIME_FORMAT format) const
+{
+ if (format == TIME_FORMAT_GUESS && GetTotalPlayTime() >= 3600)
+ format = TIME_FORMAT_HH_MM_SS;
+ float time = GetTotalPlayTime() * g_application.GetSeekHandler()->GetPercent() * 0.01f;
+ return StringUtils::SecondsToTimeString((int)time, format);
+}
+
int CGUIInfoManager::GetTotalPlayTime() const
{
int iTotalTime = (int)g_application.GetTotalTime();
@@ -651,6 +651,7 @@ class CGUIInfoManager : public IMsgTargetCallback
int64_t GetPlayTime() const; // in ms
CStdString GetCurrentPlayTime(TIME_FORMAT format = TIME_FORMAT_GUESS) const;
+ CStdString GetCurrentSeekTime(TIME_FORMAT format = TIME_FORMAT_GUESS) const;
int GetPlayTimeRemaining() const;
int GetTotalPlayTime() const;
CStdString GetCurrentPlayTimeRemaining(TIME_FORMAT format) const;
@@ -21,10 +21,9 @@
#include "GUIDialogSeekBar.h"
#include "guilib/GUISliderControl.h"
-#include "GUIUserMessages.h"
#include "Application.h"
#include "GUIInfoManager.h"
-#include "utils/StringUtils.h"
+#include "utils/SeekHandler.h"
#define POPUP_SEEK_SLIDER 401
#define POPUP_SEEK_LABEL 402
@@ -39,16 +38,6 @@ CGUIDialogSeekBar::~CGUIDialogSeekBar(void)
{
}
-bool CGUIDialogSeekBar::OnAction(const CAction &action)
-{
- if (action.GetID() == ACTION_ANALOG_SEEK_FORWARD || action.GetID() == ACTION_ANALOG_SEEK_BACK)
- {
- m_handler.Seek(action.GetID() == ACTION_ANALOG_SEEK_FORWARD, action.GetAmount(), action.GetRepeat());
- return true;
- }
- return CGUIDialog::OnAction(action);
-}
-
bool CGUIDialogSeekBar::OnMessage(CGUIMessage& message)
{
switch ( message.GetMessage() )
@@ -63,12 +52,6 @@ bool CGUIDialogSeekBar::OnMessage(CGUIMessage& message)
CGUIDialog::OnMessage(message);
}
break;
- case GUI_MSG_PLAYBACK_STARTED:
- { // new song started while our window is up - reset our seek handler
- m_handler.Reset();
- }
- break;
-
}
return false; // don't process anything other than what we need!
}
@@ -82,7 +65,7 @@ void CGUIDialogSeekBar::FrameMove()
}
// update controls
- if (!m_handler.InProgress() && !g_infoManager.m_performingSeek)
+ if (!g_application.GetSeekHandler()->InProgress() && !g_infoManager.m_performingSeek)
{ // position the bar at our current time
CGUISliderControl *pSlider = (CGUISliderControl*)GetControl(POPUP_SEEK_SLIDER);
if (pSlider && g_infoManager.GetTotalPlayTime())
@@ -96,22 +79,12 @@ void CGUIDialogSeekBar::FrameMove()
{
CGUISliderControl *pSlider = (CGUISliderControl*)GetControl(POPUP_SEEK_SLIDER);
if (pSlider)
- pSlider->SetPercentage((int)m_handler.GetPercent());
+ pSlider->SetPercentage((int)g_application.GetSeekHandler()->GetPercent());
CGUIMessage msg(GUI_MSG_LABEL_SET, GetID(), POPUP_SEEK_LABEL);
- msg.SetLabel(GetSeekTimeLabel());
+ msg.SetLabel(g_infoManager.GetCurrentSeekTime());
OnMessage(msg);
}
- // Check for seek timeout, and perform the seek
- m_handler.Process();
-
CGUIDialog::FrameMove();
}
-
-CStdString CGUIDialogSeekBar::GetSeekTimeLabel(TIME_FORMAT format)
-{
- int time = (int)(g_infoManager.GetTotalPlayTime() * m_handler.GetPercent() * 0.01f);
- return StringUtils::SecondsToTimeString(time, format);
-}
-
@@ -22,19 +22,12 @@
*/
#include "guilib/GUIDialog.h"
-#include "XBDateTime.h"
-#include "utils/SeekHandler.h"
class CGUIDialogSeekBar : public CGUIDialog
{
public:
CGUIDialogSeekBar(void);
virtual ~CGUIDialogSeekBar(void);
virtual bool OnMessage(CGUIMessage& message);
- virtual bool OnAction(const CAction &action);
virtual void FrameMove();
- float GetPercentage() {return m_handler.GetPercent();};
- CStdString GetSeekTimeLabel(TIME_FORMAT format = TIME_FORMAT_GUESS);
-protected:
- CSeekHandler m_handler;
};

0 comments on commit c1398f4

Please sign in to comment.