Author: dmeyer
Date: Sat Jan 20 20:20:58 2007
New Revision: 9016

Added:
   trunk/ui/src/video/player.py
      - copied, changed from r8908, /trunk/ui/src/audio/player.py
Removed:
   trunk/ui/src/video/plugins/mplayer.py
   trunk/ui/src/video/plugins/xine.py
Modified:
   trunk/ui/src/video/videoitem.py

Log:
o use kaa.popcorn for video playback
o adjust to new application style


Copied: trunk/ui/src/video/player.py (from r8908, /trunk/ui/src/audio/player.py)
==============================================================================
--- /trunk/ui/src/audio/player.py       (original)
+++ trunk/ui/src/video/player.py        Sat Jan 20 20:20:58 2007
@@ -1,13 +1,13 @@
 # -*- coding: iso-8859-1 -*-
 # -----------------------------------------------------------------------------
-# player.py - the Freevo audio player
+# player.py - the Freevo video player
 # -----------------------------------------------------------------------------
 # $Id$
 #
-# This module provides the audio player. It will use one of the registered
-# player plugins to play the audio item (e.g. audio.mplayer)
+# This module provides the video player. It will use one of the registered
+# player plugins to play the video item (e.g. video.mplayer)
 #
-# You can access the player by calling audioplayer()
+# You can access the player by calling videoplayer()
 #
 # -----------------------------------------------------------------------------
 # Freevo - A Home Theater PC framework
@@ -34,7 +34,7 @@
 #
 # -----------------------------------------------------------------------------
 
-__all__ = [ 'audioplayer' ]
+__all__ = [ 'videoplayer' ]
 
 # kaa imports
 import kaa.popcorn
@@ -43,46 +43,37 @@
 # Freevo imports
 import config
 import gui
-import gui.areas
 
 from event import *
-from application import Application
+from application import Application, STATUS_RUNNING, STATUS_STOPPING, \
+        STATUS_STOPPED, STATUS_IDLE, CAPABILITY_TOGGLE, CAPABILITY_PAUSE, \
+        CAPABILITY_FULLSCREEN
 
 import logging
-log = logging.getLogger('audio')
+log = logging.getLogger('video')
 
 _singleton = None
 
-def audioplayer():
+def videoplayer():
     """
-    return the global audio player object
+    return the global video player object
     """
     global _singleton
     if _singleton == None:
-        _singleton = AudioPlayer()
+        _singleton = VideoPlayer()
     return _singleton
 
 
-# Visualization events
-AUDIO_VISUAL_SHOW = Event('AUDIO_VISUAL_SHOW')
-AUDIO_VISUAL_HIDE = Event('AUDIO_VISUAL_HIDE')
-
-
-class AudioPlayer(Application):
+class VideoPlayer(Application):
     """
     basic object to handle the different player
     """
     def __init__(self):
-        Application.__init__(self, 'audioplayer', 'audio', False, True)
+        capabilities = (CAPABILITY_PAUSE,)
+        Application.__init__(self, 'videoplayer', 'video', capabilities)
         self.player = kaa.popcorn.Player()
+        self.player.set_window(gui.display._window)
         self.player.signals['failed'].connect_weak(self._play_failed)
-        self.running    = False
-        self.bg_playing = False
-        self.elapsed_timer = kaa.notifier.WeakTimer(self.elapsed)
-        
-        # register player to the skin
-        areas = ('screen', 'title', 'view', 'info')
-        self.draw_engine = gui.areas.Handler('player', areas)
 
 
     def play(self, item, player=None):
@@ -94,18 +85,20 @@
         #     return
 
         self.item = item
-        self.running = True
 
-        if self.bg_playing:
-            log.info('start new background playing')
-        else:
-            self.show()
+        # set the current item to the gui engine
+        self.engine.set_item(self.item)
+        self.status = STATUS_RUNNING
 
         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)
+
+        if item.info.get('interlaced'):
+            self.player.set_property('deinterlace', True)
+
+        # FIXME: set more properties
         self.player.play()
-        self.refresh()
 
 
     def _play_failed(self):
@@ -130,59 +123,7 @@
         # This function doesn't use the Application.stop() code here
         # because we stop and it is stopped when the child is dead.
         self.player.stop()
-        self.running = False
-
-
-    def show(self):
-        """
-        show the player gui
-        """
-        Application.show(self)
-        self.bg_playing = False
-        self.refresh()
-        self.draw_engine.show(config.GUI_FADE_STEPS)
-
-        # post event for showing visualizations
-        # FIXME: maybe this is a Signal
-        AUDIO_VISUAL_SHOW.post()
-
-
-    def hide(self):
-        """
-        hide the player gui
-        """
-        Application.hide(self)
-        self.draw_engine.hide(config.GUI_FADE_STEPS)
-        # DOES NOT WORK
-        # if self.running:
-        #   self.bg_playing = True
-
-        # post event for hiding visualizations
-        # FIXME: maybe this is a Signal
-        AUDIO_VISUAL_HIDE.post()
-
-
-    def elapsed(self):
-        """
-        Callback for elapsed time changes.
-        """
-        self.item.elapsed = round(self.player.get_position())
-        self.refresh()
-
-
-    def refresh(self):
-        """
-        update the screen
-        """
-        if not self.visible or not self.running:
-            return
-        # Calculate some new values
-        if not self.item.length:
-            self.item.remain = 0
-        else:
-            self.item.remain = self.item.length - self.item.elapsed
-        # redraw
-        self.draw_engine.draw(self.item)
+        self.status = STATUS_STOPPING
 
 
     def eventhandler(self, event):
@@ -199,7 +140,6 @@
             return True
 
         if event == PLAY_START:
-            self.elapsed_timer.start(0.2)
             self.item.eventhandler(event)
             return True
 
@@ -207,24 +147,29 @@
             # Now the player has stopped (either we called self.stop() or the
             # player stopped by itself. So we need to set the application to
             # to stopped.
-            self.stopped()
-            self.elapsed_timer.stop()
+            self.status = STATUS_STOPPED
             self.item.eventhandler(event)
+            if self.status == STATUS_STOPPED:
+                self.status = STATUS_IDLE
             return True
 
         if event == PAUSE:
             self.player.pause()
-            self.elapsed_timer.stop()
             return True
 
         if event == PLAY:
             self.player.resume()
-            self.elapsed_timer.start(0.2)
             return True
 
         if event == SEEK:
             self.player.seek(int(event.arg), kaa.popcorn.SEEK_RELATIVE)
             return True
 
+        if event == VIDEO_TOGGLE_INTERLACE:
+            interlaced = not self.player.get_property('deinterlace')
+            self.item.info['interlaced'] = interlaced
+            self.player.set_property('deinterlace', interlaced)
+            return True
+        
         # give it to the item
         return self.item.eventhandler(event)

Modified: trunk/ui/src/video/videoitem.py
==============================================================================
--- trunk/ui/src/video/videoitem.py     (original)
+++ trunk/ui/src/video/videoitem.py     Sat Jan 20 20:20:58 2007
@@ -11,7 +11,6 @@
 # TODO: o maybe split this file into file/vcd/dvd or
 #         move subitem to extra file
 #       o create better 'arg' handling in play
-#       o maybe xine options?
 #
 # -----------------------------------------------------------------------------
 # Freevo - A Home Theater PC framework
@@ -49,9 +48,8 @@
 # freevo imports
 import config
 import util
-import plugin
 
-from gui.windows import MessageBox, ConfirmBox
+from application import MessageWindow, ConfirmWindow
 from menu import Menu, MediaItem, Files, Action
 from event import *
 
@@ -59,6 +57,8 @@
 import configure
 import database
 
+from player import videoplayer
+
 # get logging object
 log = logging.getLogger('video')
 
@@ -72,17 +72,10 @@
         self.subtitle_file     = {}         # text subtitles
         self.audio_file        = {}         # audio dubbing
 
-        self.mplayer_options   = ''
-
         self.selected_subtitle = None
         self.selected_audio    = None
         self.elapsed           = 0
 
-        self.player        = None
-        self.player_rating = 0
-
-        self.possible_player   = []
-
         # set url and parse the name
         self.set_url(url)
 
@@ -135,7 +128,6 @@
                 self.info.set_variables(tvinfo[1])
                 if not self.image:
                     self.image = tvinfo[0]
-                self.mplayer_options = tvinfo[2]
             self.tv_show      = True
             self.show_name    = show_name
             self.tv_show_name = show_name[0]
@@ -302,22 +294,6 @@
         return not from_start
 
 
-    def __get_possible_player(self):
-        """
-        return a list of possible player for this item
-        """
-        possible_player = []
-        for p in plugin.getbyname(plugin.VIDEO_PLAYER, True):
-            rating = p.rate(self) * 10
-            if config.VIDEO_PREFERED_PLAYER == p.name:
-                rating += 1
-            if hasattr(self, 'force_player') and p.name == self.force_player:
-                rating += 100
-            possible_player.append((rating, p))
-        possible_player.sort(lambda l, o: -cmp(l[0], o[0]))
-        return possible_player
-
-
     # ------------------------------------------------------------------------
     # actions:
 
@@ -326,50 +302,18 @@
         """
         return a list of possible actions on this item.
         """
-        self.possible_player = self.__get_possible_player()
-
-        if not self.possible_player:
-            self.player = None
-            self.player_rating = 0
-            return []
-
-        self.player_rating, self.player = self.possible_player[0]
-
-        # For DVD and VCD check if the rating is >= 20. If it is and the url
-        # ends with '/', the user should get the DVD/VCD menu from the player.
-        # If not, we need to show the title menu.
         if self.url.startswith('dvd://') and self.url[-1] == '/':
-            if self.player_rating >= 20:
-                items = [ Action(_('Play DVD'), self.play),
-                          Action(_('DVD title list'),
-                                 self.dvd_vcd_title_menu) ]
-            else:
-                items = [ Action(_('DVD title list'), self.dvd_vcd_title_menu),
-                          Action(_('Play default track'), self.play) ]
-
+            items = [ Action(_('Play DVD'), self.play),
+                      Action(_('DVD title list'), self.dvd_vcd_title_menu) ]
         elif self.url == 'vcd://':
-            if self.player_rating >= 20:
-                items = [ Action(_('Play VCD'), self.play),
-                          Action(_('VCD title list'),
-                                 self.dvd_vcd_title_menu) ]
-            else:
-                items = [ Action(_('VCD title list'), self.dvd_vcd_title_menu),
-                          Action(_('Play default track'), self.play) ]
+            items = [ Action(_('Play VCD'), self.play),
+                      Action(_('VCD title list'), self.dvd_vcd_title_menu) ]
         else:
-            items = []
-            # Add all possible players to the action list
-            for r, player in self.possible_player:
-                a = Action(_('Play with %s') % player.name, self.play)
-                a.parameter(player=player)
-                items.append(a)
-
-        # Network play can get a larger cache
-        if self.network_play:
-            a = Action(_('Play with maximum cache'), self.play)
-            a.parameter(mplayer_options='-cache 65536')
+            items = [ Action(_('Play'), self.play) ]
 
         # Add the configure stuff (e.g. set audio language)
         items += configure.get_items(self)
+
         return items
 
 
@@ -394,10 +338,9 @@
         self.pushmenu(moviemenu)
 
 
-    def play(self, player=None, mplayer_options=''):
+    def play(self):
         """
-        Play the item. The argument 'arg' can either be a player or
-        extra mplayer arguments.
+        Play the item.
         """
         if self.subitems:
             # if we have subitems (a movie with more than one file),
@@ -408,16 +351,6 @@
 
             result = self.__set_next_available_subitem()
             if self.current_subitem: # 'result' is always 1 in this case
-                # The media is available now for playing
-                # Pass along the options, without loosing the subitem's own
-                # options
-                if self.current_subitem.mplayer_options:
-                    if self.mplayer_options:
-                        mo = self.current_subitem.mplayer_options
-                        mo += ' ' + self.mplayer_options
-                        self.current_subitem.mplayer_options = mo
-                else:
-                    self.current_subitem.mplayer_options = self.mplayer_options
                 # When playing a subitem, the menu must be hidden. If it is
                 # not, the playing will stop after the first subitem, since the
                 # PLAY_END event is not forwarded to the parent
@@ -434,8 +367,8 @@
                 # No media at all was found: error
                 txt = (_('No media found for "%s".\n')+
                        _('Please insert the media.')) % self.name
-                box = ConfirmBox(txt, (_('Retry'), _('Abort')))
-                box.connect(0, self.play)
+                box = ConfirmWindow(txt, (_('Retry'), _('Abort')))
+                box.buttons[0].connect(self.play)
                 box.show()
                 
             # done, everything else is handled in 'play' of the subitem
@@ -445,52 +378,15 @@
             # normal playback of one file
             file = self.filename
 
-        # get the correct player for this item and check the
-        # rating if the player can play this item or not
-        if not self.possible_player:
-            self.possible_player = self.__get_possible_player()
-
-        if not self.possible_player:
-            return
-
-        if not self.player:
-            # get the best possible player
-            self.player_rating, self.player = self.possible_player[0]
-            if self.player_rating < 10:
-                MessageBox(_('No player for this item found')).show()
-                return
-
-        # put together the mplayer options for this file
-        mplayer_options = self.mplayer_options.split(' ') + \
-                              mplayer_options.split(' ')
-
-        if player:
-            self.player = player
-
-        # call all our plugins to let them know we will play
-        # FIXME: use a global PLAY event here
-        # self.plugin_eventhandler(PLAY)
-
         # call the player to play the item
-        error = self.player.play(mplayer_options, self)
-
-        if error:
-            # If we are a subitem we don't show any error message before
-            # having tried all the subitems
-            if hasattr(self.parent, 'subitems') and self.parent.subitems:
-                return error
-            else:
-                box = MessageBox(error)
-                box.connect(self.stop)
-                box.show()
+        videoplayer().play(self)
 
 
     def stop(self):
         """
         stop playing
         """
-        if self.player:
-            self.player.stop()
+        videoplayer().stop()
 
 
     def eventhandler(self, event):
@@ -513,14 +409,5 @@
                         return True
                 if self.error_in_subitem:
                     # No more subitems to play, and an error occured
-                    MessageBox(self.last_error_msg).show()
-
-        # show configure menu
-        if event == MENU:
-            if self.player:
-                self.player.stop()
-            confmenu = configure.get_menu(self)
-            self.pushmenu(confmenu)
-            return True
-
+                    MessageWindow(self.last_error_msg).show()
         return MediaItem.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

Reply via email to