Author: remi
Date: 2009-03-16 16:25:57 +0100 (Mon, 16 Mar 2009)
New Revision: 4094
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-clockradio/branches/0.0.3-windows-compatible/executables/mplayer/Mplayer.py
Log:
* fixed encoding (linux)
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-clockradio/branches/0.0.3-windows-compatible/executables/mplayer/Mplayer.py
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-clockradio/branches/0.0.3-windows-compatible/executables/mplayer/Mplayer.py
2009-03-16 15:24:55 UTC (rev 4093)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-clockradio/branches/0.0.3-windows-compatible/executables/mplayer/Mplayer.py
2009-03-16 15:25:57 UTC (rev 4094)
@@ -1,166 +1,166 @@
-import os
-import subprocess
-import threading
-import time
-
-#
------------------------------------------------------------------------------
-# Mplayer stdin/stdout bridge.
-#
------------------------------------------------------------------------------
-class Mplayer(object):
- """Mplayer stdin/stdout bridge.
- """
-
- #
--------------------------------------------------------------------------
- # Constructor of the class.
- #
--------------------------------------------------------------------------
- def __init__(self):
- """Constructor of the class.
- """
- if os.name == 'nt':
- mPath, mFile = os.path.split(__file__)
- self.__appMplayer = os.path.join(mPath, 'mplayer.exe')
- else:
- self.__appMplayer = 'mplayer'
- self.__runMutex = threading.Lock()
- self.__run = False
- self.__process = None
- self.__device = self.__getTuxDroidSoundDevice()
-
- #
--------------------------------------------------------------------------
- # Get the sound device of Tux Droid.
- #
--------------------------------------------------------------------------
- def __getTuxDroidSoundDevice(self):
- """Get the sound device of Tux Droid.
- @return: A string.
- """
- if os.name == 'nt':
- from ctypes import windll
- winmm= windll.winmm
- wvcps= ' '*52
- cardsCount = winmm.waveOutGetNumDevs()
- for i in range(cardsCount):
- try:
- if winmm.waveOutGetDevCapsA(i, wvcps,len(wvcps)) == 0:
- if wvcps[8:].split("\0")[0].find("TuxDroid-Audio") ==
0:
- idx = i + 1
- return "dsound:device=%d" % idx
- except:
- pass
- return "dsound:device=1"
- else:
- return "alsa:device=plughw=TuxDroid,0"
-
- #
--------------------------------------------------------------------------
- # Start mplayer.
- #
--------------------------------------------------------------------------
- def start(self, media, async = False):
- """Start mplayer.
- @param media: Media to play.
- @param async: Run async or not.
- """
- if not async:
- self.__mainLoop(media)
- else:
- t = threading.Thread(target = self.__mainLoop, args = (media,))
- t.start()
-
- #
--------------------------------------------------------------------------
- # Stop mplayer.
- #
--------------------------------------------------------------------------
- def stop(self):
- """Stop mplayer.
- """
- if not self.__getRun():
- return
- if self.__process != None:
- if os.name == 'nt':
- handle = self.__process._handle
- else:
- pid = self.__process.pid
- if os.name == 'nt':
- import win32api
- try:
- win32api.TerminateProcess(int(handle), -1)
- except:
- pass
- else:
- os.system("kill -9 " + str(pid))
- self.__setRun(False)
- self.__process = None
- time.sleep(0.25)
-
- #
--------------------------------------------------------------------------
- # Get the pid of mplayer.
- #
--------------------------------------------------------------------------
- def getPid(self):
- """Get the pid of mplayer.
- @return: An integer.
- """
- if self.__process != None:
- if os.name == 'nt':
- return int(self.__process.pid)
- else:
- return self.__process.pid
- else:
- return None
-
- #
--------------------------------------------------------------------------
- # Get if mplayer is started or not.
- #
--------------------------------------------------------------------------
- def __getRun(self):
- """Get if mplayer is started or not.
- @return: True or False.
- """
- self.__runMutex.acquire()
- result = self.__run
- self.__runMutex.release()
- return result
-
- #
--------------------------------------------------------------------------
- # Get if mplayer is started or not.
- #
--------------------------------------------------------------------------
- def isStarted(self):
- """Get if mplayer is started or not.
- @return: True or False.
- """
- return self.__getRun()
-
- #
--------------------------------------------------------------------------
- # Set the run flag value.
- #
--------------------------------------------------------------------------
- def __setRun(self, value):
- """Set the run flag value.
- @param value: Flag value. <True|False>
- """
- self.__runMutex.acquire()
- self.__run = value
- self.__runMutex.release()
-
- #
--------------------------------------------------------------------------
- # Main loop of mplayer.
- #
--------------------------------------------------------------------------
- def __mainLoop(self, uri):
- """Main loop of mplayer.
- """
- if self.__getRun():
- return
- self.__setRun(True)
- cmd = [
- self.__appMplayer,
- "-slave",
- "-ao",
- self.__device,
- "-playlist",
- uri,
- ]
- if uri.lower().find(".m3u") == -1:
- if uri.lower().find("http") != 0:
- cmd.pop(4)
- self.__process = subprocess.Popen(
- cmd,
- stdin = subprocess.PIPE,
- stdout = subprocess.PIPE,
- stderr = subprocess.PIPE)
- while self.__getRun():
- if len(self.__process.stdout.read()) == 0:
- self.stop()
+import os
+import subprocess
+import threading
+import time
+
+#
------------------------------------------------------------------------------
+# Mplayer stdin/stdout bridge.
+#
------------------------------------------------------------------------------
+class Mplayer(object):
+ """Mplayer stdin/stdout bridge.
+ """
+
+ #
--------------------------------------------------------------------------
+ # Constructor of the class.
+ #
--------------------------------------------------------------------------
+ def __init__(self):
+ """Constructor of the class.
+ """
+ if os.name == 'nt':
+ mPath, mFile = os.path.split(__file__)
+ self.__appMplayer = os.path.join(mPath, 'mplayer.exe')
+ else:
+ self.__appMplayer = 'mplayer'
+ self.__runMutex = threading.Lock()
+ self.__run = False
+ self.__process = None
+ self.__device = self.__getTuxDroidSoundDevice()
+
+ #
--------------------------------------------------------------------------
+ # Get the sound device of Tux Droid.
+ #
--------------------------------------------------------------------------
+ def __getTuxDroidSoundDevice(self):
+ """Get the sound device of Tux Droid.
+ @return: A string.
+ """
+ if os.name == 'nt':
+ from ctypes import windll
+ winmm= windll.winmm
+ wvcps= ' '*52
+ cardsCount = winmm.waveOutGetNumDevs()
+ for i in range(cardsCount):
+ try:
+ if winmm.waveOutGetDevCapsA(i, wvcps,len(wvcps)) == 0:
+ if wvcps[8:].split("\0")[0].find("TuxDroid-Audio") ==
0:
+ idx = i + 1
+ return "dsound:device=%d" % idx
+ except:
+ pass
+ return "dsound:device=1"
+ else:
+ return "alsa:device=plughw=TuxDroid,0"
+
+ #
--------------------------------------------------------------------------
+ # Start mplayer.
+ #
--------------------------------------------------------------------------
+ def start(self, media, async = False):
+ """Start mplayer.
+ @param media: Media to play.
+ @param async: Run async or not.
+ """
+ if not async:
+ self.__mainLoop(media)
+ else:
+ t = threading.Thread(target = self.__mainLoop, args = (media,))
+ t.start()
+
+ #
--------------------------------------------------------------------------
+ # Stop mplayer.
+ #
--------------------------------------------------------------------------
+ def stop(self):
+ """Stop mplayer.
+ """
+ if not self.__getRun():
+ return
+ if self.__process != None:
+ if os.name == 'nt':
+ handle = self.__process._handle
+ else:
+ pid = self.__process.pid
+ if os.name == 'nt':
+ import win32api
+ try:
+ win32api.TerminateProcess(int(handle), -1)
+ except:
+ pass
+ else:
+ os.system("kill -9 " + str(pid))
+ self.__setRun(False)
+ self.__process = None
+ time.sleep(0.25)
+
+ #
--------------------------------------------------------------------------
+ # Get the pid of mplayer.
+ #
--------------------------------------------------------------------------
+ def getPid(self):
+ """Get the pid of mplayer.
+ @return: An integer.
+ """
+ if self.__process != None:
+ if os.name == 'nt':
+ return int(self.__process.pid)
+ else:
+ return self.__process.pid
+ else:
+ return None
+
+ #
--------------------------------------------------------------------------
+ # Get if mplayer is started or not.
+ #
--------------------------------------------------------------------------
+ def __getRun(self):
+ """Get if mplayer is started or not.
+ @return: True or False.
+ """
+ self.__runMutex.acquire()
+ result = self.__run
+ self.__runMutex.release()
+ return result
+
+ #
--------------------------------------------------------------------------
+ # Get if mplayer is started or not.
+ #
--------------------------------------------------------------------------
+ def isStarted(self):
+ """Get if mplayer is started or not.
+ @return: True or False.
+ """
+ return self.__getRun()
+
+ #
--------------------------------------------------------------------------
+ # Set the run flag value.
+ #
--------------------------------------------------------------------------
+ def __setRun(self, value):
+ """Set the run flag value.
+ @param value: Flag value. <True|False>
+ """
+ self.__runMutex.acquire()
+ self.__run = value
+ self.__runMutex.release()
+
+ #
--------------------------------------------------------------------------
+ # Main loop of mplayer.
+ #
--------------------------------------------------------------------------
+ def __mainLoop(self, uri):
+ """Main loop of mplayer.
+ """
+ if self.__getRun():
+ return
+ self.__setRun(True)
+ cmd = [
+ self.__appMplayer,
+ "-slave",
+ "-ao",
+ self.__device,
+ "-playlist",
+ uri,
+ ]
+ if uri.lower().find(".m3u") == -1:
+ if uri.lower().find("http") != 0:
+ cmd.pop(4)
+ self.__process = subprocess.Popen(
+ cmd,
+ stdin = subprocess.PIPE,
+ stdout = subprocess.PIPE,
+ stderr = subprocess.PIPE)
+ while self.__getRun():
+ if len(self.__process.stdout.read()) == 0:
+ self.stop()
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn