search instagram arrow-down

Archives

Categories

Meta

Command Line Audio Player using Python

Gstreamer  is the Opensource  multimedia Framework. The applications it supports range from simple Ogg/Vorbis playback, audio/video streaming to complex audio (mixing) and video (non-linear editing) processing.

Here, we use the gstreamer through Python to play the audio file. (mp3,wav etc). —usage ptyhon audio-player.py <File to Play>

<pre>#!/usr/bin/python
import pygst,sys
pygst.require("0.10")
import gst
import pygtk
import gtk

class Main:
def __init__(self):
# Create the pipeline.
self.pipeline = gst.Pipeline("mypipeline")
self.filesrc = gst.element_factory_make("filesrc", "source")

self.filesrc.set_property("location", sys.argv[1])
self.decode = gst.element_factory_make("decodebin", "decode")
self.decode.connect("new-decoded-pad", self.OnDynamicPad)
self.convert = gst.element_factory_make("audioconvert", "convert")
self.sink = gst.element_factory_make("alsasink", "sink")
# add the elements to the pipeline.
self.pipeline.add(self.filesrc,self.decode,self.convert,self.sink)
# Link them.
self.filesrc.link(self.decode)
self.convert.link(self.sink)
# state in Playing mode.
self.pipeline.set_state(gst.STATE_PLAYING)

def OnDynamicPad(self, dbin, pad, islast):
print "OnDynamicPad Called!"
pad.link(self.convert.get_pad("sink"))

start=Main()
gtk.main()
Leave a Reply
Your email address will not be published. Required fields are marked *

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: