Author: dmeyer
Date: Tue Jan 23 13:18:44 2007
New Revision: 9048
Modified:
trunk/ui/src/audio/__init__.py
trunk/ui/src/audio/audioitem.py
trunk/ui/src/audio/player.py
trunk/ui/src/video/__init__.py
trunk/ui/src/video/player.py
trunk/ui/src/video/videoitem.py
Log:
more cleanup in audio and video player
Modified: trunk/ui/src/audio/__init__.py
==============================================================================
--- trunk/ui/src/audio/__init__.py (original)
+++ trunk/ui/src/audio/__init__.py Tue Jan 23 13:18:44 2007
@@ -1,31 +1,25 @@
# -*- coding: iso-8859-1 -*-
-# -----------------------------------------------------------------------
-# __init__.py
-# -----------------------------------------------------------------------
+# -----------------------------------------------------------------------------
+# __init__.py - interface to audio
+# -----------------------------------------------------------------------------
# $Id$
#
# This file imports everything needed to use this audio module.
# There is only one class provided for audio files, the PluginInterface
# from interface.py. It is a MimetypePlugin that can be accessed
# from plugin.mimetype(). It will also register an fxd handler for the
-# <audio> tag.
+# <playlist> tag.
#
# Audio plugins are also allowed to use AudioItem to create a new AudioItem
-# and audioplayer, a function to return the player application
#
-# Notes:
-# Todo:
-#
-# -----------------------------------------------------------------------
-# $Log$
-# Revision 1.26 2004/09/13 19:34:24 dischi
-# move interface/fxdhandler into extra file
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002-2007 Krister Lagerstrom, Dirk Meyer, et al.
#
+# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
+# Maintainer: Dirk Meyer <[EMAIL PROTECTED]>
#
-# -----------------------------------------------------------------------
-# Freevo - A Home Theater PC framework
-# Copyright (C) 2002-2005 Krister Lagerstrom, Dirk Meyer, et al.
-# Please see the file doc/CREDITS for a complete list of authors.
+# Please see the file AUTHORS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -41,10 +35,9 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# ----------------------------------------------------------------------- */
+# -----------------------------------------------------------------------------
from interface import *
# used by audio plugins
from audioitem import AudioItem
-from player import audioplayer
Modified: trunk/ui/src/audio/audioitem.py
==============================================================================
--- trunk/ui/src/audio/audioitem.py (original)
+++ trunk/ui/src/audio/audioitem.py Tue Jan 23 13:18:44 2007
@@ -45,7 +45,7 @@
from menu import MediaItem, Action
from event import *
-from player import *
+import player as audioplayer
import logging
log = logging.getLogger('audio')
@@ -61,7 +61,6 @@
self.elapsed = 0
self.remain = 0
self.pause = 0
- self.mplayer_options = ''
try:
self.length = int(self.info['length'])
except:
@@ -128,11 +127,11 @@
Start playing the item
"""
self.elapsed = 0
- audioplayer().play(self)
+ audioplayer.play(self)
def stop(self):
"""
Stop the current playing
"""
- audioplayer().stop()
+ audioplayer.stop()
Modified: trunk/ui/src/audio/player.py
==============================================================================
--- trunk/ui/src/audio/player.py (original)
+++ trunk/ui/src/audio/player.py Tue Jan 23 13:18:44 2007
@@ -6,8 +6,9 @@
#
# -----------------------------------------------------------------------------
# Freevo - A Home Theater PC framework
-# Copyright (C) 2002-2005 Krister Lagerstrom, Dirk Meyer, et al.
+# Copyright (C) 2002-2007 Krister Lagerstrom, Dirk Meyer, et al.
#
+# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
# Maintainer: Dirk Meyer <[EMAIL PROTECTED]>
#
# Please see the file AUTHORS for a complete list of authors.
@@ -28,12 +29,13 @@
#
# -----------------------------------------------------------------------------
-__all__ = [ 'audioplayer' ]
+__all__ = [ 'play', 'stop' ]
# python imports
import logging
# kaa imports
+import kaa.utils
import kaa.popcorn
import kaa.notifier
@@ -48,24 +50,7 @@
# get logging object
log = logging.getLogger('audio')
-_singleton = None
-
-def audioplayer():
- """
- Return the global audio player object
- """
- global _singleton
- if _singleton == None:
- _singleton = AudioPlayer()
- return _singleton
-
-
-# Visualization events
-AUDIO_VISUAL_SHOW = Event('AUDIO_VISUAL_SHOW')
-AUDIO_VISUAL_HIDE = Event('AUDIO_VISUAL_HIDE')
-
-
-class AudioPlayer(Application):
+class Player(Application):
"""
Audio player object.
"""
@@ -77,7 +62,7 @@
self.elapsed_timer = kaa.notifier.WeakTimer(self.elapsed)
- def play(self, item, player=None):
+ def play(self, item):
"""
play an item
"""
@@ -107,22 +92,24 @@
blocked['AUDIO'].signals['stop'].connect_once(self.play, item)
return True
- # store item and playlist
+ # Store item and playlist. We need to keep the playlist object
+ # here to make sure it is not deleted when player is running in
+ # the background.
self.item = item
self.playlist = self.item.get_playlist()
if self.playlist:
self.playlist.select(self.item)
# Calculate some new values
- if not self.item.length:
- self.item.remain = 0
- else:
+ self.item.remain = 0
+ if self.item.length:
self.item.remain = self.item.length - self.item.elapsed
- # set the current item to the gui engine
+ # Set the current item to the gui engine
self.engine.set_item(self.item)
self.status = STATUS_RUNNING
+ # Open media item and start playback
self.player.open(self.item.url)
self.player.signals['end'].connect_once(PLAY_END.post, self.item)
self.player.signals['start'].connect_once(PLAY_START.post, self.item)
@@ -148,8 +135,8 @@
"""
Stop playing.
"""
- # This function doesn't use the Application.stop() code here
- # because we stop and it is stopped when the child is dead.
+ if self.get_status() != STATUS_RUNNING:
+ return True
self.player.stop()
self.status = STATUS_STOPPING
@@ -194,12 +181,9 @@
Callback for elapsed time changes.
"""
self.item.elapsed = round(self.player.get_position())
- # Calculate some new values
- if not self.item.length:
- self.item.remain = 0
- else:
+ self.item.remain = 0
+ if self.item.length:
self.item.remain = self.item.length - self.item.elapsed
- # redraw
self.engine.update()
@@ -208,8 +192,6 @@
React on some events or send them to the real player or the
item belongig to the player
"""
- # FIXME: handle next player on PLAY_END when there was an error
-
if event == STOP:
# Stop the player and pass the event to the item
self.stop()
@@ -246,5 +228,12 @@
self.player.seek(int(event.arg), kaa.popcorn.SEEK_RELATIVE)
return True
- # give it to the item
return self.item.eventhandler(event)
+
+
+# create singleton object
+player = kaa.utils.Singleton(Player)
+
+# create functions to use from the outside
+play = player.play
+stop = player.stop
Modified: trunk/ui/src/video/__init__.py
==============================================================================
--- trunk/ui/src/video/__init__.py (original)
+++ trunk/ui/src/video/__init__.py Tue Jan 23 13:18:44 2007
@@ -14,12 +14,12 @@
#
# -----------------------------------------------------------------------------
# Freevo - A Home Theater PC framework
-# Copyright (C) 2002-2005 Krister Lagerstrom, Dirk Meyer, et al.
+# Copyright (C) 2002-2007 Krister Lagerstrom, Dirk Meyer, et al.
#
# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
# Maintainer: Dirk Meyer <[EMAIL PROTECTED]>
#
-# Please see the file doc/CREDITS for a complete list of authors.
+# Please see the file AUTHORS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Modified: trunk/ui/src/video/player.py
==============================================================================
--- trunk/ui/src/video/player.py (original)
+++ trunk/ui/src/video/player.py Tue Jan 23 13:18:44 2007
@@ -29,12 +29,13 @@
#
# -----------------------------------------------------------------------------
-__all__ = [ 'videoplayer' ]
+__all__ = [ 'play', 'stop' ]
# python imports
import logging
# kaa imports
+import kaa.utils
import kaa.popcorn
import kaa.notifier
@@ -49,19 +50,7 @@
# get logging object
log = logging.getLogger('video')
-_singleton = None
-
-def videoplayer():
- """
- Return the global video player object.
- """
- global _singleton
- if _singleton == None:
- _singleton = VideoPlayer()
- return _singleton
-
-
-class VideoPlayer(Application):
+class Player(Application):
"""
Video player object.
"""
@@ -73,7 +62,7 @@
self.player.signals['failed'].connect_weak(self._play_failed)
- def play(self, item, player=None):
+ def play(self, item):
"""
play an item
"""
@@ -122,9 +111,7 @@
in_progress = blocked['AUDIO'].pause()
if isinstance(in_progress, kaa.notifier.InProgress):
# takes some time, wait
- cb = kaa.notifier.Callback(self.play, item)
- cb.set_ignore_caller_args()
- in_progress.connect(cb)
+ in_progress.connect(self.play, item).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)
@@ -170,8 +157,8 @@
"""
Stop playing.
"""
- # This function doesn't use the Application.stop() code here
- # because we stop and it is stopped when the child is dead.
+ if self.get_status() != STATUS_RUNNING:
+ return True
self.player.stop()
self.status = STATUS_STOPPING
@@ -181,8 +168,6 @@
React on some events or send them to the real player or the
item belongig to the player
"""
- # FIXME: handle next player on PLAY_END when there was an error
-
if event == STOP:
# Stop the player and pass the event to the item
self.stop()
@@ -223,3 +208,11 @@
# give it to the item
return self.item.eventhandler(event)
+
+
+# create singleton object
+player = kaa.utils.Singleton(Player)
+
+# create functions to use from the outside
+play = player.play
+stop = player.stop
Modified: trunk/ui/src/video/videoitem.py
==============================================================================
--- trunk/ui/src/video/videoitem.py (original)
+++ trunk/ui/src/video/videoitem.py Tue Jan 23 13:18:44 2007
@@ -57,7 +57,7 @@
import configure
import database
-from player import videoplayer
+import player as videoplayer
# get logging object
log = logging.getLogger('video')
@@ -379,14 +379,14 @@
file = self.filename
# call the player to play the item
- videoplayer().play(self)
+ videoplayer.play(self)
def stop(self):
"""
stop playing
"""
- videoplayer().stop()
+ videoplayer.stop()
def eventhandler(self, event):
-------------------------------------------------------------------------
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