coding utf-8 import gobject gobject threads_init import gst class Play

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
import gobject
gobject.threads_init()
import gst
class Player():
def __init__(self):
self.player = gst.Pipeline("player")
source = gst.element_factory_make("filesrc", "filesrc")
decoder = gst.element_factory_make("decodebin2", "decodebin2")
conv = gst.element_factory_make("audioconvert", "converter")
volume = gst.element_factory_make("volume", "volume")
sink = gst.element_factory_make("autoaudiosink", "alsa-output")
self.player.add(source, decoder, conv, volume, sink)
gst.element_link_many(source, decoder)
gst.element_link_many(conv, volume, sink)
def new_decode_pad(dbin, pad, islast):
pad.link(conv.get_pad("sink"))
decoder.connect("new-decoded-pad", new_decode_pad)
def play_track(self, track):
self.player.set_state(gst.STATE_NULL)
self.player.get_by_name("filesrc").set_property("location", track)
self.player.set_state(gst.STATE_PLAYING)
from time import sleep
p = Player()
p.play_track('track1.mp3')
sleep(3)
p.play_track('track2.mp3')
sleep(3)
p.play_track('track3.mp3')
sleep(10)