[maemo-developers] Python and GStreamer
From: Tony Maro tonymaro at gmail.comDate: Sun Aug 26 23:51:34 EEST 2007
- Previous message: Is there a Red Pill for the N770?
- Next message: Python and GStreamer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I've been trying to figure out how to use gstreamer to play audio. It
works, but sometimes it will randomly freeze my application when I try to
start an mp3 file playing. I'm only using two mp3 files and they both work
at other times (like after a reboot) so I know it's not specifically the
file.
Sometimes I'll start my application which calls the start method of the
SoundControl class below - and no sound starts. Then, when my app tries to
stop the music, everything freezes up. It always seems to freeze things
when I call "stop"
After doing this, my application refuses to work at all (always freezes)
until I reboot my n800.
If anyone has any ideas, I'd greatly appreciate it. Yes, I know there's
probably more optimized ways to do some of what I have in this class, but
it's grown as I've learned gstreamer, and I haven't stopped to refactor it
yet.
I've gleaned most of this code by looking at ukmp:
class SoundControl(object):
def __init__(self):
print "Creating music player"
self.createGSTPlayer()
def createGSTPlayer(self):
print "Creating player"
self.player = gst.parse_launch( "gnomevfssrc name=source !
dspmp3sink name=sink" ) # id3lib name=id3 !
self.source = self.player.get_by_name( "source" )
self.sink = self.player.get_by_name( "sink" )
self.player.set_name("player")
bus = self.player.get_bus()
bus.add_signal_watch()
bus.connect('message', self.on_message)
print "Player created"
def start(self, filename, newVolume = 80, repeat=-1):
if filename == None: return
self.stop()
time.sleep(0.10)
self.createGSTPlayer()
self.filename = filename
self.repeat = repeat
self.paused = False
if newVolume < 0: newVolume = 0
if newVolume > 100: newVolume = 100
# self.player.set_property('uri','file://' + filename)
print "Setting player location"
self.source.set_property("location", filename)
self.sink.set_property('volume', newVolume*65535/100)
self.player.set_state(gst.STATE_PLAYING)
print "Player should be playing"
def stop(self):
print "stopping player"
self.player.set_state(gst.STATE_NULL)
def pause(self, state=None):
print "Pause toggle"
if state == None:
if self.paused == True:
self.paused = False
self.player.set_state(gst.STATE_PLAYING)
return
self.paused = True
self.player.set_state(gst.STATE_PAUSED)
return
if state == True:
self.player.set_state(gst.STATE_PAUSED)
else:
self.player.set_state(gst.STATE_PLAYING)
def on_message(self, bus, message):
t = message.type
if t == gst.MESSAGE_EOS:
if self.repeat == -1:
print "Repeat enabled"
time_format = gst.Format(gst.FORMAT_TIME)
self.player.seek_simple(time_format, gst.SEEK_FLAG_FLUSH, 0)
self.player.set_state(gst.STATE_PLAYING)
return
if self.repeat > 0:
print "Repeat enabled"
self.repeat = self.repeat - 1
time_format = gst.Format(gst.FORMAT_TIME)
self.player.seek_simple(time_format, gst.SEEK_FLAG_FLUSH, 0)
self.player.set_state(gst.STATE_PLAYING)
return
print "No repeat, stopping"
self.player.set_state(gst.STATE_NULL)
elif t == gst.MESSAGE_ERROR:
print "Streamer error"
self.player.set_state(gst.STATE_NULL)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maemo.org/pipermail/maemo-developers/attachments/20070826/d94f62f8/attachment.htm
- Previous message: Is there a Red Pill for the N770?
- Next message: Python and GStreamer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
