gstreamer playbin - 在Windows上设置uri
我正在尝试使用这个网站上的命令行示例来播放一些音频文件:
http://pygstdocs.berlios.de/pygst-tutorial/playbin.html
我在使用Windows系统时,读取文件时出现了错误。我指定了以下路径:
$ python cliplayer.py C:\\voice.mp3
0:00:00.125000000 3788 009DA010 ERROR basesrc
gstbasesrc.c:2834:gst_base_src_activate_pull:<source> Failed to start in
pull mode
Error: Could not open resource for reading.
..\..\..\Source\gst-plugins-base\ext\gio\gstgiosrc.c(324):
gst_gio_src_get_stream ():
/GstPlayBin2:player/GstURIDecodeBin:uridecodebin0/GstGioSrc:source:
Could not open location file:///C:/file:/C:/voice.mp3 for reading: Error
opening file: Invalid argument
在Windows上,我应该如何指定文件路径呢?
另外,在这行代码中,我需要做什么特别的处理吗?
self.player.set_property("uri", "file://" + filepath)
谢谢!
2 个回答
4
你有没有注意到你得到的实际路径是 file:///C:/file:/C:/voice.mp3
呢?
正确的路径应该是: file:///C:/path/to/voice.mp3
。
9
你可能已经猜到了,这段代码写得很糟糕:
for filepath in sys.argv[1:]:
# ...
self.player.set_property("uri", "file://" + filepath)
可以用这样的方式:
'file:' + urllib.pathname2url(filepath)
在命令行中,指定文件路径时要用正常的Windows格式,比如 C:\a\b.mp3
。