Update of /cvsroot/freevo/freevo/WIP/Ruelle
In directory sc8-pr-cvs1:/tmp/cvs-serv28460

Added Files:
        fxmms.py 
Log Message:
getting xmms to work again

--- NEW FILE: fxmms.py ---
#if 0 /*
# -----------------------------------------------------------------------
# mplayer.py - the Freevo MPlayer plugin for audio
# -----------------------------------------------------------------------
# $Id: fxmms.py,v 1.1 2003/12/23 21:48:21 mikeruelle Exp $
#
# Notes:
# Todo:        
#
# -----------------------------------------------------------------------
# $Log: fxmms.py,v $
# Revision 1.1  2003/12/23 21:48:21  mikeruelle
# getting xmms to work again
#
# Revision 1.30  2003/12/13 14:27:19  outlyer
# Since ChildApp2 defaults to stopping the OSD, stop_osd=0 needs to be defined
# here or the audio player will try to stop the display and then try to write
# to the screen (and crash)
#
# Revision 1.29  2003/12/10 19:10:35  dischi
# AUDIO_PLAY_END is not needed anymore
#
# Revision 1.28  2003/12/10 19:02:38  dischi
# move to new ChildApp2 and remove the internal thread
#
# Revision 1.27  2003/12/06 13:43:35  dischi
# expand the <audio> parsing in fxd files
#
# Revision 1.26  2003/11/22 15:30:55  dischi
# support more than one player
#
# Revision 1.25  2003/11/11 18:01:44  dischi
# fix playback problems with fxd files (and transform to list app style)
#
# Revision 1.24  2003/11/08 13:21:18  dischi
# network m3u support, added AUDIOCD plugin register
#
# Revision 1.23  2003/10/21 21:17:41  gsbarbieri
# Some more i18n improvements.
#
# Revision 1.22  2003/10/20 13:36:07  outlyer
# Remove the double-quit
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al. 
# Please see the file freevo/Docs/CREDITS 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif

# regular python imports
import os
import re
import sys
import time

# pyxmms import
try:
    import xmms
except ImportError:
    print
    print
    print 'pyxmms is not (properly?) installed!'
    print
    sys.exit(1)

# freevo imports
import config     # Configuration handler. reads config file.
import childapp   # Handle child applications
import rc
import plugin
from event import *


class PluginInterface(plugin.Plugin):
    """
    XMMS plugin for the audio player. Use xmms to play all audio
    files.
    """
    def __init__(self):
        # create the plugin object
        plugin.Plugin.__init__(self)

        # register mplayer as the object to play audio
        plugin.register(FXMMS(), plugin.AUDIO_PLAYER, True)


class FXMMS:
    """
    the main class to control mplayer
    """
    
    def __init__(self):
        self.name     = 'xmms'
        self.app_mode = 'audio'
        self.app      = None


    def rate(self, item):
        """
        How good can this player play the file:
        2 = good
        1 = possible, but not good
        0 = unplayable
        """
        if item.filename.startswith('cdda://'):
            return 1
        return 2

    def play(self, item, playerGUI):
        """
        play a audioitem with mplayer
        """
        if item.url:
            filename = item.url
        else:
            filename = item.filename

        self.playerGUI = playerGUI
        
        # Do we care if the file streamed over the network?

        if not os.path.isfile(filename) and filename.find('://') == -1:
            return _('%s\nnot found!') % filename
            
        # Build the command
        command = '--prio=%s %s %s' % (config.MPLAYER_NICE,
                                          config.XMMS_CMD,
                                          config.XMMS_ARGS_DEF)

        # do we need to make these for xmms too?
        #extra_opts = item.mplayer_options

        # handle looping
        #if hasattr(item, 'reconnect') and item.reconnect:
        #    extra_opts += ' -loop 0'
            
        #may need to add extra options here for looping and  item options

        command = command.replace('\n', '').split(' ')

        command.append(filename)

        print "MFR DEBUG: '%s'" % command
        
        if plugin.getbyname('MIXER'):
            plugin.getbyname('MIXER').reset()

        self.item = item

        if not self.item.valid:
            # Invalid file, show an error and survive.
            return _('Invalid audio file')

        _debug_('FXMMS.play(): Starting cmd=%s' % command)
            
        self.app = XMMSPlayerApp(command, self)
        # need this sleep. occasionally xmms will show without it
        time.sleep(0.2)
        xmms.main_win_toggle(0)
        return None
    

    def stop(self):
        """
        Stop mplayer
        """
        xmms.stop()
        xmms.quit()


    def is_playing(self):
        return xmms.is_running()


    def refresh(self):
        curtime = xmms.get_output_time()
        curtime = int(curtime / 1000)
        self.elapsed = self.item.elapsed = curtime
        self.playerGUI.refresh()
        

    def eventhandler(self, event, menuw=None):
        """
        eventhandler for xmms. If an event is not bound in this
        function it will be passed over to the items eventhandler
        """

        if event == PLAY_END and event.arg:
            self.stop()
            if self.playerGUI.try_next_player():
                return True
            
        if event in ( STOP, PLAY_END, USER_END ):
            self.playerGUI.stop()
            return self.item.eventhandler(event)

        elif event == PAUSE or event == PLAY:
            xmms.pause()
            return True

        elif event == SEEK:
            curtime = xmms.get_output_time()
            nexttime = curtime + (event.arg * 1000)
            xmms.jump_to_time(nexttime)
            return True

        else:
            # everything else: give event to the items eventhandler
            return self.item.eventhandler(event)
            
            
# ======================================================================

class XMMSPlayerApp(childapp.ChildApp2):
    """
    class controlling the in and output from the xmms process
    """
    def __init__(self, app, player):
        self.item        = player.item
        self.player      = player
        self.elapsed     = 0
        self.stop_reason = 0 # 0 = ok, 1 = error
        childapp.ChildApp2.__init__(self, app, stop_osd=0)


    def stop_event(self):
        return Event(PLAY_END, self.stop_reason, handler=self.player.eventhandler)

        
    def stdout_cb(self, line):
        pass

    def stderr_cb(self, line):
        if line.startswith('Failed to open'):
            self.stop_reason = 1




-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to