import pygtk gtk gobject from PyQt4 import QtCore QtGui import gst fro

 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pygtk, gtk, gobject
from PyQt4 import QtCore, QtGui
import gst
from time import sleep
from threading import Thread
from Track import Track
from Buffer import Buffer
from Length import Length
import os
class Source(gst.BaseSrc):
__gsttemplates__ = (
gst.PadTemplate("src",
gst.PAD_SRC,
gst.PAD_ALWAYS,
gst.caps_new_any()),
)
def __init__(self, config, track, buf):
self.__gobject_init__()
self.buf = buf
def do_create(self, offset, size):
data = self.buf.file.read(size)
if data:
#self.curoffset += len(data)
return gst.FLOW_OK, gst.Buffer(data)
else:
return gst.FLOW_UNEXPECTED, None
gobject.type_register(Source)
class Player(QtCore.QObject):
def __init__(self, config, track, proc):
self.buf = Buffer(track, config = config)
self.buf.start()
self.player = gst.Pipeline("player")
source = Source(config, track, self.buf)
decoder = gst.element_factory_make("mad", "mp3-decoder")
conv = gst.element_factory_make("audioconvert", "converter")
sink = gst.element_factory_make("alsasink", "alsa-output")
self.player.add(source, decoder, conv, sink)
gst.element_link_many(source, decoder, conv, sink)
def start(self):
self.play()
def play(self):
self.player.set_state(gst.STATE_PLAYING)
def stop(self):
self.player.set_state(gst.STATE_NULL)
def pause(self):
self.player.set_state(gst.STATE_PAUSED)
def seek(self):
pass
def cur_time(self):
return 10
def total_time(self):
return 10