如何解决寻求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 举报,一经查实,本站将立刻删除。