我有一个使用 Python、PyGObject (Gtk 3) 和 GStreamer (0.11) 的项目
我的应用程序中有视频,所以我使用了 Gtk.Overlay 小部件,这样我就可以将其他视觉元素放在视频背景上。(我需要这个,相信我。)(由于小部件的数量,以及这些小部件的特定定位和覆盖的需要,我使用的是 Gtk.Fixed 容器。)
但是,在使用带有通过“overlay.add_overlay(widget)”添加的任何内容的 Gtk.Overlay 对象时,视频根本不再可见。我仍然可以听到它,但我看不到它。
代码如下。
from gi.repository import Gtk, Gdk, GdkPixbuf, GdkX11
import pango
import pygst
pygst.require('0.10')
import gst
import Trailcrest
import os, sys
import cairo
from math import pi
class Video:
def __init__(self):
def on_message(bus, message):
if message.type == gst.MESSAGE_EOS:
# End of Stream
player.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, 5000000000, gst.SEEK_TYPE_NONE, 6000000000)
elif message.type == gst.MESSAGE_ERROR:
player.set_state(gst.STATE_NULL)
(err, debug) = message.parse_error()
print "Error: %s" % err, debug
def on_sync_message(bus, message):
if message.structure is None:
return False
if message.structure.get_name() == "prepare-xwindow-id":
Gdk.threads_enter()
Gdk.Display.get_default().sync()
win_id = videowidget.get_property('window').get_xid()
imagesink = message.src
imagesink.set_property("force-aspect-ratio", True)
imagesink.set_xwindow_id(win_id)
Gdk.threads_leave()
def click_me(event, data=None):
player.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, 5000000000, gst.SEEK_TYPE_NONE, 6000000000)
win = Gtk.Window()
win.set_resizable(False)
win.set_decorated(False)
win.set_position(Gtk.WindowPosition.CENTER)
overlay = Gtk.Overlay()
win.add(overlay)
overlay.show()
videowidget = Gtk.DrawingArea()
overlay.add(videowidget)
videowidget.set_halign (Gtk.Align.START)
videowidget.set_valign (Gtk.Align.START)
videowidget.set_size_request(640, 480)
videowidget.show()
fixed = Gtk.Fixed()
overlay.add_overlay(fixed)
fixed.show()
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size("IMG/IMG-MPG-LOGO.png", 250, 50)
imgMPL = Gtk.Image()
imgMPL.set_from_pixbuf(pixbuf)
eb_imgMPL = Gtk.EventBox()
eb_imgMPL.set_visible_window(False)
eb_imgMPL.add(imgMPL)
fixed.put(eb_imgMPL, 10, 10)
imgMPL.show()
eb_imgMPL.show()
win.show_all()
# Setup GStreamer
player = gst.element_factory_make("playbin", "MultimediaPlayer")
bus = player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
#used to get messages that GStreamer emits
bus.connect("message", on_message)
#used for connecting video to your application
bus.connect("sync-message::element", on_sync_message)
player.set_property("uri", "file://" + os.getcwd() + "/VID/BGA-HABT-001.ogv")
player.set_state(gst.STATE_PLAYING)
if __name__ == "__main__":
Gdk.threads_enter()
Video()
Gtk.main()
我该如何解决这个小问题?