Author: dmeyer
Date: Mon Apr 9 18:10:51 2007
New Revision: 9424
Modified:
trunk/ui/src/audio/player.py
trunk/ui/src/video/player.py
Log:
adjust to new resource code, patch by Mathias Weber
Modified: trunk/ui/src/audio/player.py
==============================================================================
--- trunk/ui/src/audio/player.py (original)
+++ trunk/ui/src/audio/player.py Mon Apr 9 18:10:51 2007
@@ -44,8 +44,8 @@
from freevo.ui.event import *
from freevo.ui.application import Application, STATUS_RUNNING,
STATUS_STOPPING, \
- STATUS_STOPPED, STATUS_IDLE, CAPABILITY_TOGGLE, CAPABILITY_PAUSE, \
- CAPABILITY_FULLSCREEN
+ STATUS_STOPPED, STATUS_IDLE, CAPABILITY_TOGGLE, CAPABILITY_PAUSE, \
+ CAPABILITY_FULLSCREEN
# get logging object
log = logging.getLogger('audio')
@@ -66,6 +66,7 @@
"""
play an item
"""
+ retry = kaa.notifier.Callback(self.play, item)
if not self.status in (STATUS_IDLE, STATUS_STOPPED):
# Already running, stop the current player by sending a STOP
# event. The event will also get to the playlist behind the
@@ -73,7 +74,7 @@
Event(STOP, handler=self.eventhandler).post()
# Now connect to our own 'stop' signal once to repeat this current
# function call without the player playing
- self.signals['stop'].connect_once(self.play, item)
+ self.signals['stop'].connect_once(retry)
return True
if not kaa.notifier.running:
@@ -84,12 +85,15 @@
# Try to get AUDIO resource. The ressouce will be freed by the system
# when the application switches to STATUS_STOPPED or STATUS_IDLE.
blocked = self.get_resources('AUDIO')
- if 'AUDIO' in blocked:
- # Something has the audio resource blocked, stop it
- Event(STOP, handler=blocked['AUDIO'].eventhandler).post()
- # Now connect to the 'stop' signal once to repeat this current
- # function call without the player playing
- blocked['AUDIO'].signals['stop'].connect_once(self.play, item)
+ if blocked == False:
+ log.error("Can't get Audio resource.")
+ return False
+ if len(blocked) != 0:
+ status = self.suspend_all(blocked)
+ if isinstance(status, kaa.notifier.InProgress):
+ status.connect(retry)
+ return True
+ retry()
return True
# Store item and playlist. We need to keep the playlist object
@@ -141,41 +145,6 @@
self.status = STATUS_STOPPING
- @kaa.notifier.yield_execution()
- def pause(self):
- """
- Pause Playback. Return False if already paused.
- """
- # FIXME: make sure this function is not called twice
- if not self.status == STATUS_RUNNING:
- yield False
- if self.player.get_state() == kaa.popcorn.STATE_PAUSED:
- yield None
- # FIXME: what happens if we send pause() the same time the file
- # is finished? This would create a race condition.
- self.player.pause()
- yield kaa.notifier.YieldCallback(self.player.signals['pause'])
- self.free_resources()
-
-
- @kaa.notifier.yield_execution()
- def resume(self):
- """
- Resume Playback. Return False if already resumed.
- """
- # FIXME: make sure this function is not called twice
- if not self.status == STATUS_RUNNING:
- yield False
- if self.player.get_state() == kaa.popcorn.STATE_PLAYING:
- yield False
- if self.get_resources('AUDIO'):
- # FIXME: what to do in this case?
- log.error('unable to get AUDIO ressource')
- yield False
- self.player.resume()
- yield kaa.notifier.YieldCallback(self.player.signals['play'])
-
-
def elapsed(self):
"""
Callback for elapsed time changes.
@@ -216,7 +185,7 @@
if event in (PAUSE, PLAY):
if self.player.get_state() == kaa.popcorn.STATE_PLAYING:
- self.pause()
+ self.suspend()
return True
if self.player.get_state() == kaa.popcorn.STATE_PAUSED:
self.resume()
@@ -230,6 +199,50 @@
return self.item.eventhandler(event)
+ def can_suspend(self):
+ """
+ Return true since the application can be suspended.
+ """
+ return True
+
+ @kaa.notifier.yield_execution()
+ def suspend(self):
+ """
+ Release the audio resource that others can use it.
+ """
+ # FIXME: make sure this function is not called twice
+ if not self.status == STATUS_RUNNING:
+ yield False
+ if self.player.get_state() == kaa.popcorn.STATE_PAUSED:
+ yield None
+ # FIXME: what happens if we send pause() the same time the file
+ # is finished? This would create a race condition.
+ self.player.pause()
+ yield kaa.notifier.YieldCallback(self.player.signals['pause'])
+ self.free_resources()
+
+
+ @kaa.notifier.yield_execution()
+ def resume(self):
+ """
+ Resume playing the audio, at the position before.
+ """
+ # FIXME: make sure this function is not called twice
+ if not self.status == STATUS_RUNNING:
+ yield False
+ if self.player.get_state() == kaa.popcorn.STATE_PLAYING:
+ yield False
+ blocked = self.get_resources('AUDIO')
+ if blocked == False:
+ # FIXME: what to do in this case?
+ log.error('unable to get AUDIO ressource')
+ yield False
+ elif len(blocked) > 0:
+ yield self.suspend_all(blocked)
+ self.player.resume()
+ yield kaa.notifier.YieldCallback(self.player.signals['play'])
+
+
# create singleton object
player = kaa.utils.Singleton(Player)
Modified: trunk/ui/src/video/player.py
==============================================================================
--- trunk/ui/src/video/player.py (original)
+++ trunk/ui/src/video/player.py Mon Apr 9 18:10:51 2007
@@ -44,8 +44,8 @@
from freevo.ui.event import *
from freevo.ui.application import Application, STATUS_RUNNING,
STATUS_STOPPING, \
- STATUS_STOPPED, STATUS_IDLE, CAPABILITY_TOGGLE, CAPABILITY_PAUSE, \
- CAPABILITY_FULLSCREEN
+ STATUS_STOPPED, STATUS_IDLE, CAPABILITY_TOGGLE, CAPABILITY_PAUSE, \
+ CAPABILITY_FULLSCREEN
# get logging object
log = logging.getLogger('video')
@@ -68,6 +68,7 @@
play an item
"""
retry = kaa.notifier.Callback(self.play, item, player)
+ retry.set_ignore_caller_args(True)
if not self.status in (STATUS_IDLE, STATUS_STOPPED):
# Already running, stop the current player by sending a STOP
# event. The event will also get to the playlist behind the
@@ -87,38 +88,17 @@
# by the system when the application switches to STATUS_STOPPED or
# STATUS_IDLE.
blocked = self.get_resources('AUDIO', 'VIDEO')
- if 'VIDEO' in blocked:
- # Something has the video resource blocked. The only application
- # possible is the tv player right now. It would be possible to
- # ask the user what to do with a popup but we assume the user
- # does not care about the tv and just stop it.
- Event(STOP, handler=blocked['VIDEO'].eventhandler).post()
- # Now connect to the 'stop' signal once to repeat this current
- # function call without the player playing
- blocked['VIDEO'].signals['stop'].connect_once(retry)
- return True
- if 'AUDIO' in blocked:
- # AUDIO is blocked, VIDEO is not. This is most likely the audio
- # player and we can pause it. Do this if possible.
- if not blocked['AUDIO'].has_capability(CAPABILITY_PAUSE):
- # Unable to pause, just stop it
- Event(STOP, handler=blocked['AUDIO'].eventhandler).post()
- # Now connect to the 'stop' signal once to repeat this current
- # function call without the player playing
- blocked['AUDIO'].signals['stop'].connect_once(retry)
+ if blocked == False:
+ log.error("Can't get resource AUDIO, VIDEO")
+ return False
+ if len(blocked) > 0:
+ status = self.suspend_all(blocked)
+ if isinstance(status, kaa.notifier.InProgress):
+ status.connect(retry)
return True
- # Now pause the current player. On its pause signal this player can
- # play again. And on the stop signal of this player (STATUS_IDLE)
- # the other player can be resumed again.
- in_progress = blocked['AUDIO'].pause()
- if isinstance(in_progress, kaa.notifier.InProgress):
- # takes some time, wait
- in_progress.connect(retry).set_ignore_caller_args()
- if in_progress is not False:
- # we paused the application, resume on our stop
- self.signals['stop'].connect_once(blocked['AUDIO'].resume)
+ retry()
return True
-
+
# store item and playlist
self.item = item
self.playlist = self.item.get_playlist()
@@ -179,6 +159,44 @@
self.item.elapsed = round(self.player.get_position())
+ def can_suspend(self):
+ """
+ Return true since the video player can be suspended. It is more likely
+ to be stoped, but still it will release the resource.
+ """
+ return True
+
+ @kaa.notifier.yield_execution()
+ def suspend(self):
+ """
+ Release the audio and video resource.
+ """
+ if not self.status == STATUS_RUNNING:
+ yield False
+ if self.player.get_state == kaa.popcorn.STATE_PAUSED:
+ yield False
+ self.player.stop()
+ self.status = STATUS_STOPPING
+ yield kaa.notifier.YieldCallback(self.player.signals['stop'])
+ self.free_resources()
+ yield True
+
+
+ def resume(self):
+ """
+ Resume video. At the moment do nothing so video is only stoped, but
+ does not restart. TODO
+ """
+ if not self.status == STATUS_RUNNING:
+ return False
+ if self.player.get_state == kaa.popcorn.STATUS_RUNNING:
+ return False
+ # since we don't pause the video player we stop it restart everything
+ # that was running before.
+ self.resume_all()
+ return True
+
+
def eventhandler(self, event):
"""
React on some events or send them to the real player or the
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog