2014-10-04 140 views
0

我試圖與Tkinter的,GStreamer的和python3視頻播放器,我有以下代碼「NoneType」對象有沒有屬性「set_property」 Tkinter的,GStreamer的python3

import sys, os 
from tkinter import * 
from gi.repository import GObject 
from gi.repository import GLib 
from gi.repository import Gtk 
from gi.repository import Gst 
def start(): 
     player.set_property('video-sink', None) 
     player.set_property("uri", "./video.avi") 
     player.set_state(Gst.STATE_PLAYING) 

def on_sync_message(bus, message): 
     if message.structure is None: 
       return 
     message_name = message.structure.get_name() 
     if message_name == "prepare-xwindow-id": 
       imagesink = message.src 
       imagesink.set_property("force-aspect-ratio", True) 
       imagesink.set_xwindow_id(mwin_id) 

window = Tk() 
window.geometry("500x400") 
movie_window = Frame(window,bg='#000000') 
movie_window.pack(side=BOTTOM,anchor=S,expand=YES,fill=BOTH) 

mwin_id = movie_window.winfo_id() 

player = Gst.ElementFactory.make("playbin2", "player") 
fakesink = Gst.ElementFactory.make("fakesink", "fakesink") 
player.set_property("video-sink", fakesink) 


bus = player.get_bus() 
bus.add_signal_watch() 
bus.enable_sync_message_emission() 
bus.connect("sync-message::element", on_sync_message) 


window.mainloop() 
start() 

,但我收到錯誤:

(reproductor4.py:6856): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized()' failed 
Traceback (most recent call last): 
    File "reproductor4.py", line 30, in <module> 
    player.set_property("video-sink", fakesink) 
AttributeError: 'NoneType' object has no attribute 'set_property' 

爲什麼會出現這種情況的一些想法?

回答

0

第30行是player.set_property("video-sink", fakesink)。跟蹤和屬性錯誤消息似乎聲稱player是無。在該行之前使用print(player)進行測試。但是,我不明白Traceback之前的額外信息。它表明gst代碼中的斷言失敗。

0

你的問題其實是:在你的代碼

(reproductor4.py:6856): GStreamer-CRITICAL **: gst_element_factory_make: assertion `gst_is_initialized()' failed 

沒有被調用初始化程序:gst_init()(很可能是Gst.init()在python)。如果沒有初始化,gstreamer將無法工作。

+0

非常感謝你最後我不得不初始化對象,只有追加: GObject.threads_init() Gst.init(無) – grijalvaromero 2014-10-05 04:58:10

0

的solucion是這樣的臺詞: 最後只追加這樣的行前致電: GObject.threads_init() Gst.init(無)

相關問題