我試圖與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'
爲什麼會出現這種情況的一些想法?
非常感謝你最後我不得不初始化對象,只有追加: GObject.threads_init() Gst.init(無) – grijalvaromero 2014-10-05 04:58:10