from time import sleep from PyQt4 import QtCore from vplayer bufferer

 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
64
65
66
67
68
69
70
71
from time import sleep
from PyQt4 import QtCore
from vplayer.bufferer import Buffer
from vplayer.logger import log
class Source(QtCore.QIODevice):
def __init__(self, track):
QtCore.QIODevice.__init__(self)
self.track = track
self.buf = Buffer(track)
self.buf.start()
self.pos = 0
def atEnd(self):
self.wait_for_buffer()
return self.buf.length == self.pos
def size(self):
self.wait_for_buffer()
log.debug('Size request returns %d' % self.buf.length)
return long(self.buf.length)
def readData(self, maxsize):
need = self.pos + maxsize
if need > self.buf.length:
need = self.buf.length
self.wait_for_buffer(need)
if self.pos < len(self.buf.data):
data = self.buf.data[self.pos:self.pos+maxsize]
else:
data = bytes()
log.debug('Read %d bytes' % len(data))
self.pos += len(data)
log.debug('Pos is now %d' % self.pos)
return data
def writeData(*args):
return False
def seek(self, pos):
QtCore.QIODevice.seek(self, pos)
log.debug('Seek req: %d' % pos)
self.pos = pos
return True
# def bytesAvailable(self):
# self.wait_for_buffer()
# return self.buf.length - self.pos + QtCore.QIODevice.bytesAvailable()
def isSequential(self):
return False#not self.track.local
#False
def wait_for_buffer(self, pos = 0):
while not self.buf.length and not self.buf.failed:
sleep(0.01)
if pos:
while self.buf.pos < pos and not self.buf.failed:
sleep(0.01)
if self.buf.failed:
log.error('Buffer failed')
def pos(self):
log.debug('Pos request')
return self.pos
def reset(self):
self.pos = 0
return True