[gst-devel] playing a playlist without stopping the sink

Sander Marechal s.marechal at jejik.com
Wed Sep 12 01:14:27 CEST 2007


Hello all,

I have been trying for a long time now to get a simple player working
that can play through a playlist and obey a simple "next" command,
without setting the pipeline to STATE_NULL (because in the final
version, the output will be a shout2send sink[1])

I've written a simplified, minimal version of my player, but I can't
even get that to work :-( I always get gstreamer errors when I switch to
the next song, and usually output stops alltogether. Or it hangs.

I have attached my minimal player below. When you run it, simply typing
"next" and hitting return should start playing the next song. I'm
probably doing something fundamentally wrong here.

I haven't been able to find any examples online that implement something
similar. It's either gstreamer tutorials that do "set STATE_NULL, change
location on filesrc, set STATE_PLAYING" or trying to comprehend the
source of advanced players/managers that do quite complicated stuff with
pipelines that I really don't understand.

Could someone point out to me what I'm doing wrong?

Thanks in advance,

-- 
Sander Marechal

[1] When a pipeline goes to STATE_NULL, the shout2send will unmount the
stream from icecast and all the icecast listeners get disconnected.

playlist.py:
============
#!/usr/bin/env python

import pygst, gobject, time, sys
pygst.require("0.10")
import gst

class AudioPlayer:
	def __init__(self):
		self.songs = [
			'music/Ozzy/Mr. Tinkertrain.mp3',
			'music/Ozzy/I Don\'t Want to Change the World.mp3',
			'music/Ozzy/Mama, I\'m Coming Home.mp3 ',
			'music/Ozzy/Desire.mp3',
			'music/Ozzy/No More Tears.mp3 ',
			'music/Ozzy/S.I.N..mp3',
			'music/Ozzy/Hellraiser.mp3',
		]
		
		# create a new gstreamer pipeline
		self.pipeline = gst.Pipeline("mypipeline")
		
		# add a file source to the pipeline
		self.filesrc = gst.element_factory_make("filesrc", "source")
		self.pipeline.add(self.filesrc)
		
		# add a generic decoder to the pipeline and link it to the source
		self.decode = gst.element_factory_make("decodebin", "decode")
		self.decode.connect("new-decoded-pad", self.decode_link)
		self.pipeline.add(self.decode)
		self.filesrc.link(self.decode)
		
		# add a convertor to the pipeline
		self.convert = gst.element_factory_make("audioconvert", "convert")
		self.pipeline.add(self.convert)
		
		# add an alsa sink to the pipeline and link it to the convertor
		self.sink = gst.element_factory_make("alsasink", "sink")
		self.pipeline.add(self.sink)
		self.convert.link(self.sink)
		
		# start playing
		self.filesrc.set_property("location", self.songs.pop(0))
		self.pipeline.set_state(gst.STATE_PLAYING)

	def decode_link(self, dbin, pad, islast):
		pad.link(self.convert.get_pad("sink"))
	
	def next(self):
		self.convert.unlink(self.sink)
		self.filesrc.set_state(gst.STATE_NULL)
		self.filesrc.set_property("location", self.songs.pop(0))
		self.convert.link(self.sink)
		self.pipeline.set_state(gst.STATE_PLAYING)
		return True

player = AudioPlayer()
loop = gobject.MainLoop()
gobject.threads_init()
context = loop.get_context()

while 1:
	value = sys.stdin.readline()
	if value == "next\n":
		player.next()
	context.iteration(True)




More information about the gstreamer-devel mailing list