2002-10-03 22:11:37 +00:00
|
|
|
#!/usr/bin/env python
|
2002-03-24 11:41:24 +00:00
|
|
|
#
|
|
|
|
# gst-python
|
|
|
|
# Copyright (C) 2002 David I. Lehn
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Library General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Library General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Library General Public
|
|
|
|
# License along with this library; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
# Boston, MA 02111-1307, USA.
|
|
|
|
#
|
2002-12-17 17:40:42 +00:00
|
|
|
# Author: David I. Lehn <dlehn@users.sourceforge.net>
|
2002-03-24 11:41:24 +00:00
|
|
|
#
|
2002-03-24 07:49:36 +00:00
|
|
|
|
2002-03-24 11:41:24 +00:00
|
|
|
import sys
|
2002-03-24 07:49:36 +00:00
|
|
|
from gstreamer import *
|
|
|
|
|
|
|
|
def main():
|
|
|
|
"Basic example to play an Ogg Vorbis stream through OSS"
|
|
|
|
#gst_debug_set_categories(-1)
|
|
|
|
|
|
|
|
if len(sys.argv) != 2:
|
|
|
|
print 'usage: %s <Ogg Vorbis file>' % (sys.argv[0])
|
|
|
|
return -1
|
|
|
|
|
|
|
|
# create a new bin to hold the elements
|
2002-10-03 22:11:37 +00:00
|
|
|
bin = Pipeline('pipeline')
|
2002-03-24 07:49:36 +00:00
|
|
|
|
|
|
|
# create a disk reader
|
2002-04-15 17:14:31 +00:00
|
|
|
filesrc = gst_element_factory_make ('filesrc', 'disk_source');
|
2002-03-24 07:49:36 +00:00
|
|
|
if not filesrc:
|
|
|
|
print 'could not find plugin \"filesrc\"'
|
|
|
|
return -1
|
|
|
|
filesrc.set_property('location', sys.argv[1])
|
|
|
|
|
|
|
|
# now get the decoder
|
2003-01-01 00:20:46 +00:00
|
|
|
decoder = gst_element_factory_make ('vorbisfile', 'parse');
|
2002-03-24 07:49:36 +00:00
|
|
|
if not decoder:
|
2003-01-01 00:20:46 +00:00
|
|
|
print 'could not find plugin \"vorbisfile\"'
|
2002-03-24 07:49:36 +00:00
|
|
|
return -1
|
|
|
|
|
|
|
|
# and an audio sink
|
2002-04-15 17:14:31 +00:00
|
|
|
osssink = gst_element_factory_make ('osssink', 'play_audio')
|
2002-03-24 07:49:36 +00:00
|
|
|
if not osssink:
|
|
|
|
print 'could not find plugin \"osssink\"'
|
|
|
|
return -1
|
|
|
|
|
|
|
|
# add objects to the main pipeline
|
|
|
|
for e in (filesrc, decoder, osssink):
|
|
|
|
bin.add(e)
|
|
|
|
|
|
|
|
# connect the elements
|
|
|
|
previous = None
|
|
|
|
for e in (filesrc, decoder, osssink):
|
|
|
|
if previous:
|
2002-04-15 23:51:21 +00:00
|
|
|
previous.connect(e)
|
2002-03-24 07:49:36 +00:00
|
|
|
previous = e
|
|
|
|
|
|
|
|
# start playing
|
|
|
|
bin.set_state(STATE_PLAYING);
|
|
|
|
|
|
|
|
while bin.iterate(): pass
|
|
|
|
|
|
|
|
# stop the bin
|
|
|
|
bin.set_state(STATE_NULL)
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
ret = main()
|
|
|
|
sys.exit(ret)
|