我正在寻找播放歌曲的方法,而不是从python gstreamer的开头播放,请考虑一下:
import threading
import gst
import gobject
class GobInit(threading.Thread):
...
class BasicPlayer(threading.Thread):
def __init__(self, musiclist):
threading.Thread.__init__(self)
self.musiclist = musiclist
self.song_num = 0
self.construct_pipeline()
self.set_property_file()
def construct_pipeline(self):
self.player = gst.element_factory_make("playbin")
self.is_playing = False
self.connect_signals()
def connect_signals(self):
...
def play(self):
self.is_playing = True
self.player.set_state(gst.STATE_PLAYING)
def set_property_file(self):
self.player.set_property(
"uri", "file://"+"/home/user/work/mp3/"+self.musiclist[
self.song_num])
def main():
gob = GobInit()
gob.start()
print('start')
player = BasicPlayer(['test1.mp3', 'test2.mp3', 'test3.mp3'])
print('player created')
player.play()
print('start play')
main()
所以我只有这个功能才能开始:
self.player.set_state(gst.STATE_PLAYING)
但是我打赌有一种方法可以从歌曲的中间开始播放,类似这样:
self.player.play_from_middle(gst.STATE_PLAYING, <sec_after_begin>)
或者也许我可以以某种方式回放这首歌以使其从中间播放?
答案 0 :(得分:4)
是的,我想应该有几种方法,但我脑子里想到的那种方式(对于非实时流)是: