寻求https音频中断播放的Python GStreamer

问题描述

这是脚本的第一部分:

import os,gi,time
from threading import Thread
gi.require_version('Gst','1.0')
from gi.repository import Gst,GLib

Gst.init()

main_loop = GLib.MainLoop()
thread = Thread(target=main_loop.run)
thread.start()

url = os.popen(f"youtube-dl --format m4a --get-url https://www.youtube.com/watch?v=ndl1W4ltcmg").read()

之后,我可以使用souphttpssrc :

player = Gst.parse_launch(f"souphttpsrc is-live=false location={url} ! decodebin ! audioconvert ! autoaudiosink")

或播放箱:

player = Gst.parse_launch(f"playbin uri={url}")

然后启动它,然后稍等:

player.set_state(Gst.State.PLAYING)
time.sleep(1)

最后我尝试在 TIME 中寻找:

player.seek_simple(Gst.Format.TIME,Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT,20 * Gst.SECOND)

或以字节为单位:

player.seek_simple(Gst.Format.BYTES,120000)

这里是脚本的结尾:

try:
    while True:
        time.sleep(0.1)
except KeyboardInterrupt:
    pass

player.set_state(Gst.State.NULL)
main_loop.quit()

两者都返回True,但随着TIME 播放立即停止(状态也变为暂停,但切换回播放没有帮助)。不过,这可能与 this 问题有关。

这就是为什么我尝试了BYTES,它在寻找到 120000 后继续播放,但不久后停止(大约 180000 字节),这里的状态仍然是 PLAYING,但也没有声音。

有什么办法可以使用 GStreamer 寻找流式音频吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)