繁体   English   中英

使用gstreamer,在不停止接收器的情况下播放播放列表

[英]using gstreamer, playing a playlist without stopping the sink

我想向音乐播放器添加播放列表功能。 播放列表中的第一首曲目。 在控制台中键入“ next”并按回车键应开始播放下一首曲目,但歌曲停止播放,并且什么也没有发生。

在更改“位置”之前将状态设置为GST_STATE_READY而不是GST_STATE_NULL也不起作用。

有人可以更正我的代码并告诉我哪里错了吗?

import pygst, gobject, time, sys
pygst.require("0.10")
import gst

class AudioPlayer:
         def __init__(self):
                 self.songs = ['Holy Diver.mp3','Paranoid.mp3','Fast as a Shark.mp3']

                 # create a new gstreamer pipeline
                 self.pipeline = gst.Pipeline("mypipeline")

                 # add a file source to the pipeline
                 self.filesrc = gst.element_factory_make("filesrc","source")
                 self.pipeline.add(self.filesrc)

                 # add a generic decoder to the pipeline and link it to thesource
                 self.decode = gst.element_factory_make("decodebin","decode")
                 self.decode.connect("new-decoded-pad", self.decode_link)
                 self.pipeline.add(self.decode)
                 self.filesrc.link(self.decode)

                 # add a convertor to the pipeline
                 self.convert = gst.element_factory_make("audioconvert","convert")
                 self.pipeline.add(self.convert)

                 # add an alsa sink to the pipeline and link it to theconvertor
                 self.sink = gst.element_factory_make("alsasink", "sink")
                 self.pipeline.add(self.sink)
                 self.convert.link(self.sink)

                 # start playing
                 self.filesrc.set_property("location", self.songs.pop(0))
                 self.pipeline.set_state(gst.STATE_PLAYING)

         def decode_link(self, dbin, pad, islast):
                 pad.link(self.convert.get_pad("sink"))

         def next(self):
                 self.convert.unlink(self.sink)
                 self.filesrc.set_state(gst.STATE_NULL)
                 self.filesrc.set_property("location", self.songs.pop(0))
                 self.convert.link(self.sink)
                 self.pipeline.set_state(gst.STATE_PLAYING)
                 return True

player = AudioPlayer()
loop = gobject.MainLoop()
gobject.threads_init()
context = loop.get_context()

while 1:
         value = sys.stdin.readline()
         if value == "next\n":
                 player.next()
         context.iteration(True)

接下来,您将错误的内容设置为NULL:
self.filesrc.set_state(gst.STATE_NULL)

应该
self.pipeline.set_state(gst.STATE_NULL)

那就是问题的症结所在,您没有停止管道,但也不需要取消链接和重新链接self.convert,但这是一个附带问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM