有没有办法在 gstreamer 中从中间播放歌曲?
Is there a way to play song from the middle in gstreamer?
我一直在寻找在 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>)
或者我能否以某种方式倒带歌曲以使其从中间播放?
是的,我想应该有几种方法,但我立即想到的一种(对于非直播)是:
- 将管道设置为暂停而不是播放
- 等待 GST_MESSSAGE_ASYNC_DONE 消息出现在总线处理程序中。
- 查询管道(gst_element_query())持续时间,然后寻找管道(gst_element_seek())到duration/2时间
- 将管道设置为播放。
我一直在寻找在 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>)
或者我能否以某种方式倒带歌曲以使其从中间播放?
是的,我想应该有几种方法,但我立即想到的一种(对于非直播)是:
- 将管道设置为暂停而不是播放
- 等待 GST_MESSSAGE_ASYNC_DONE 消息出现在总线处理程序中。
- 查询管道(gst_element_query())持续时间,然后寻找管道(gst_element_seek())到duration/2时间
- 将管道设置为播放。