[maemo-developers] Python and GStreamer
From: Leonardo Sobral Cunha sobral at gmail.comDate: Mon Aug 27 18:29:21 EEST 2007
- Previous message: Python and GStreamer
- Next message: Python and GStreamer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
hi tony,
there is a bug in your code, you dont need to call createGSTPlayer in
the start method, so you will reuse the pipeline that is already
created in the constructor (__init__).
I have tested your code (without the createGSTPlayer in the start
method) with the test code below and it worked fine.
if __name__ == '__main__':
argv = os.sys.argv
argc = len(argv)
if argc != 2:
print 'Pass filename as parameter'
exit
filename = argv[1]
sc = SoundControl()
sc.start(filename)
time.sleep(2)
print "restarting"
sc.stop()
sc.start(filename)
time.sleep(2)
print "end"
BR,
--
// leo
-------------------------------------------------------
Leonardo Sobral Cunha
INdT - Instituto Nokia de Tecnologia
PGP: 0x5751676C @ wwwkeys.pgp.net
-------------------------------------------------------
On 8/26/07, Tony Maro <tonymaro at gmail.com> wrote:
> 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)
>
>
> _______________________________________________
> maemo-developers mailing list
> maemo-developers at maemo.org
> https://lists.maemo.org/mailman/listinfo/maemo-developers
>
>
--
// leo
- Previous message: Python and GStreamer
- Next message: Python and GStreamer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
