簡體   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