2010-02-07 86 views
2

我試圖發揮在這個網站與CLI例如一些音頻文件:的GStreamer playbin - 設置URI在Windows

http://pygstdocs.berlios.de/pygst-tutorial/playbin.html 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) 

謝謝!

回答

9

正如你可能已經懷疑,此代碼,而寫的不好:

for filepath in sys.argv[1:]: 
    # ... 
    self.player.set_property("uri", "file://" + filepath) 

使用這樣的事情:

'file:' + urllib.pathname2url(filepath) 

,並(在命令行)指定正常的Windows文件路徑符號,例如C:\a\b.mp3

+1

urllib.pathname2url是一個很好的建議...我沒有嘗試過,但看起來它會工作... btw還有另一種方法filename_to_uri ...沒有檢查它做什麼,但應該轉換路徑去... ...。另一方面,file:///(三斜槓)解決了Windows上的問題。 – cppb 2010-02-08 05:29:25

4

您是否注意到您擁有的實際路徑是file:///C:/file:/C:/voice.mp3

正確的路徑應該是:file:///C:/path/to/voice.mp3

+0

是的。關鍵是文件///(注意三重斜線!) – cppb 2010-02-08 05:26:58