Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9 from anaconda/paused-background
Jump back in the background on pause.
  • Loading branch information
Memphiz committed Nov 9, 2014
2 parents c26aee5 + 4c485e3 commit a6a15f3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion script.xbmc.unpausejumpback/addon.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.xbmc.unpausejumpback" name="XBMC Unpause Jumpback" version="2.3.1" provider-name="Memphiz|Lucleonhart|schumi2004|bossanova808">
<addon id="script.xbmc.unpausejumpback" name="XBMC Unpause Jumpback" version="2.3.2" provider-name="Memphiz|Lucleonhart|schumi2004|bossanova808">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
</requires>
Expand Down
5 changes: 4 additions & 1 deletion script.xbmc.unpausejumpback/changelog.txt
@@ -1,4 +1,7 @@
V2.3.1
2.3.2
- jump back "in the background" when paused (i.e. while still paused instead of upon resuming)

2.3.1
- revert jumpback after playback started due to XBMC video timer bug - can not add this until xbmc properly reports the playback position immediately on playback start

2.3.0
Expand Down
43 changes: 17 additions & 26 deletions script.xbmc.unpausejumpback/default.py
Expand Up @@ -18,7 +18,6 @@
import xbmcaddon
import xbmcgui
import os
from time import time

__addon__ = xbmcaddon.Addon()
__cwd__ = __addon__.getAddonInfo('path')
Expand Down Expand Up @@ -46,10 +45,8 @@
global g_jumpBackSecsAfterRwdX32
global g_jumpBackSecsAfterResume
global g_lastPlaybackSpeed
global g_pausedTime
global g_waitForJumpback
g_jumpBackSecsAfterFwdPause = 0
g_pausedTime = 0
g_waitForJumpback = 0
g_lastPlaybackSpeed = 1

Expand Down Expand Up @@ -136,9 +133,17 @@ def __init__( self, *args, **kwargs ):
log('MyPlayer - init')

def onPlayBackPaused( self ):
global g_pausedTime
g_pausedTime = time()
log('Paused. Time: %d' % g_pausedTime)
global g_jumpBackSecsAfterFwdPause
global g_waitForJumpback

if self.isPlayingVideo():
_filename = self.getPlayingFile()
if isExcluded(_filename):
log("Playback paused - ignoring because '%s' is in exclusion settings." % _filename)
elif g_jumpBackSecsAfterFwdPause > 0 and self.getTime() > g_jumpBackSecsAfterFwdPause:
percentage = (self.getTime() - g_jumpBackSecsAfterFwdPause) / self.getTotalTime() * 100
log('Playback paused, setting up alarm clock - getTime()=%f getTotalTime()=%f g_jumpBackSecsAfterFwdPause=%d percentage=%f' % (self.getTime(), self.getTotalTime(), g_jumpBackSecsAfterFwdPause, percentage))
xbmc.executebuiltin('AlarmClock(JumpbackPaused, PlayerControl(SeekPercentage(%f)), 0:%d, silent)' % (percentage, g_waitForJumpback))

def onPlayBackSpeedChanged( self, speed ):
global g_lastPlaybackSpeed
Expand Down Expand Up @@ -181,26 +186,12 @@ def onPlayBackSpeedChanged( self, speed ):
g_lastPlaybackSpeed = speed

def onPlayBackResumed( self ):
global g_jumpBackSecsAfterFwdPause
global g_pausedTime
global g_waitForJumpback
if g_pausedTime > 0:
log('Resuming. Was paused for %d seconds.' % (time() - g_pausedTime))

# check for exclusion
_filename = self.getPlayingFile()
if isExcluded(_filename):
log("Ignored because '%s' is in exclusion settings." % _filename)
return

else:
#handle humpback after pause
if g_jumpBackSecsAfterFwdPause != 0 and xbmc.Player().isPlayingVideo() and xbmc.Player().getTime() > g_jumpBackSecsAfterFwdPause and g_pausedTime > 0 and (time() - g_pausedTime) > g_waitForJumpback:
resumeTime = xbmc.Player().getTime() - g_jumpBackSecsAfterFwdPause
xbmc.Player().seekTime(resumeTime)
log( 'Resumed with %ds jumpback' % g_jumpBackSecsAfterFwdPause )

g_pausedTime = 0
log('Cancelling alarm - playback either resumed or stopped by the user')
xbmc.executebuiltin('CancelAlarm(JumpbackPaused, true)')

# We don't care if playback was resumed or stopped, we just want to know when we're no longer paused
onPlayBackStopped = onPlayBackResumed

try:
class MyMonitor( xbmc.Monitor ):
def __init__( self, *args, **kwargs ):
Expand Down

0 comments on commit a6a15f3

Please sign in to comment.