summaryrefslogtreecommitdiff
path: root/src/msd/msd_player.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/msd/msd_player.py')
-rw-r--r--src/msd/msd_player.py156
1 files changed, 80 insertions, 76 deletions
diff --git a/src/msd/msd_player.py b/src/msd/msd_player.py
index 1a3a9e7..5d1ca97 100644
--- a/src/msd/msd_player.py
+++ b/src/msd/msd_player.py
@@ -18,13 +18,18 @@
# Mark Ryan <mark.d.ryan@intel.com>
#
-import pygtk
-pygtk.require('2.0')
-import glib
-import gtk
-import pygst
-pygst.require("0.10")
-import gst
+import gi
+gi.require_version('Gtk', '3.0')
+gi.require_version('Gdk', '3.0')
+gi.require_version('Gst', '1.0')
+from gi.repository import GLib, Gtk, Gst, Gdk, GdkPixbuf
+
+# For window.get_xid()
+from gi.repository import GdkX11
+
+# For xvimagesink.set_window_handle()
+from gi.repository import GstVideo
+
import datetime
from msd_utils import *
@@ -36,10 +41,11 @@ class PlayWindowBase(object):
self.__url = url
self.__close_window = close_window
- self.__container = gtk.VBox(False, 0)
- self.drawing_area = gtk.DrawingArea()
- self.private_area = gtk.VBox(True, 0)
- self.ok_button = gtk.Button("Close")
+ self.__container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+ self.drawing_area = Gtk.DrawingArea()
+ self.private_area = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
+ homogeneous=True)
+ self.ok_button = Gtk.Button("Close")
self.ok_button.connect("clicked", self.quit)
self.__container.pack_start(self.drawing_area, True, True, 0)
self.__container.pack_start(self.private_area, False, False, 0)
@@ -54,10 +60,9 @@ class PlayWindowBase(object):
def cancel_playback(self):
pass
- def draw_image(self, image):
+ def draw_image(self, image, context):
x = 0
y = 0
- gc = self.drawing_area.get_style().fg_gc[gtk.STATE_NORMAL]
rect = self.drawing_area.get_allocation()
width_scale = image.get_width() / float(rect.width)
height_scale = image.get_height() / float(rect.height)
@@ -78,9 +83,9 @@ class PlayWindowBase(object):
scaled_image = image.scale_simple(int(image.get_width() / divisor),
int(image.get_height() / divisor),
- gtk.gdk.INTERP_BILINEAR)
- self.drawing_area.window.draw_pixbuf(gc, scaled_image, 0, 0, x,
- y, -1, -1)
+ GdkPixbuf.InterpType.BILINEAR)
+ Gdk.cairo_set_source_pixbuf (context, scaled_image, x, y)
+ context.paint()
class PlayWindowImage(PlayWindowBase):
@@ -90,14 +95,15 @@ class PlayWindowImage(PlayWindowBase):
try:
image = image_from_file(url)
self.__image = image.get_pixbuf()
- self.drawing_area.connect("expose-event", self.__draw)
+ self.drawing_area.connect("draw", self.__draw)
except Exception:
pass
self.get_container().show_all()
- def __draw(self, area, event):
- self.draw_image(self.__image)
+ def __draw(self, widget, context):
+ if self.__image:
+ self.draw_image(self.__image, context)
return True
class GStreamerWindow(PlayWindowBase):
@@ -105,28 +111,28 @@ class GStreamerWindow(PlayWindowBase):
def __init__(self, name, url, close_window):
PlayWindowBase.__init__(self, name, url, close_window)
- self.player = gst.element_factory_make("playbin2", "player")
+ self.player = Gst.ElementFactory.make("playbin", "player")
gsbus = self.player.get_bus()
gsbus.add_signal_watch()
gsbus.connect("message", self.gs_message_cb)
self.player.set_property("uri", url)
- button_bar = gtk.HBox(False, 6)
-
- align = gtk.Alignment(0.5, 0.5, 0.0, 0.0)
+ button_bar = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
+ spacing=6)
+ align = Gtk.Alignment.new(0.5, 1.0, 0.0, 0.0)
button_bar.pack_start(align, False, False, 0)
- self.__play_pause_button = gtk.Button()
+ self.__play_pause_button = Gtk.Button()
self.__play_pause_button.connect("clicked", self.__play_pause)
- self.__play_pause_image = gtk.Image()
- self.__play_pause_image.set_from_stock(gtk.STOCK_MEDIA_PAUSE,
- gtk.ICON_SIZE_BUTTON)
+ self.__play_pause_image = Gtk.Image()
+ self.__play_pause_image.set_from_stock(Gtk.STOCK_MEDIA_PAUSE,
+ Gtk.IconSize.BUTTON)
self.__play_pause_button.add(self.__play_pause_image)
align.add(self.__play_pause_button)
- self.__scale = gtk.HScale()
- self.__adjustment = gtk.Adjustment(0, 0, 0,
+ self.__scale = Gtk.HScale()
+ self.__adjustment = Gtk.Adjustment(0, 0, 0,
1.0, 30.0, 1.0)
self.__adjustment.connect("value-changed", self.__adjusted)
self.__scale.set_adjustment(self.__adjustment)
@@ -137,38 +143,35 @@ class GStreamerWindow(PlayWindowBase):
self.get_container().show_all()
self.__update_pos_id = 0
- self.__state = gst.STATE_NULL
- self.player.set_state(gst.STATE_PLAYING)
+ self.__state = Gst.State.NULL
+ self.player.set_state(Gst.State.PLAYING)
def __play_pause(self, button):
- if (self.__state == gst.STATE_PLAYING):
- self.player.set_state(gst.STATE_PAUSED)
+ if (self.__state == Gst.State.PLAYING):
+ self.player.set_state(Gst.State.PAUSED)
else:
- self.player.set_state(gst.STATE_PLAYING)
+ self.player.set_state(Gst.State.PLAYING)
def __update_pos(self, user_data=None):
- try:
- pos = self.player.query_position(gst.FORMAT_TIME, None)[0]
- if pos != -1:
- pos = pos / 1000000000.0
- self.__adjustment.handler_block_by_func(self.__adjusted)
- self.__adjustment.set_value(pos)
- self.__adjustment.handler_unblock_by_func(self.__adjusted)
- except Exception:
- pass
+ success, pos = self.player.query_position(Gst.Format.TIME)
+ if success:
+ pos = pos / 1000000000.0
+ self.__adjustment.handler_block_by_func(self.__adjusted)
+ self.__adjustment.set_value(pos)
+ self.__adjustment.handler_unblock_by_func(self.__adjusted)
return True
def cancel_playback(self):
- self.player.set_state(gst.STATE_NULL)
+ self.player.set_state(Gst.State.NULL)
def quit(self, button):
- self.player.set_state(gst.STATE_NULL)
+ self.player.set_state(Gst.State.NULL)
PlayWindowBase.quit(self, button)
def __seek (self, position):
- self.player.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH,
- gst.SEEK_TYPE_SET, position,
- gst.SEEK_TYPE_NONE, -1.0)
+ self.player.seek(1.0, Gst.Format.TIME, Gst.SeekFlags.FLUSH,
+ Gst.SeekType.SET, position,
+ Gst.SeekType.NONE, -1.0)
def __adjusted(self, adjustment):
self.__seek(adjustment.get_value() * 1000000000.0)
@@ -182,37 +185,34 @@ class GStreamerWindow(PlayWindowBase):
return
self.__state = state
- if (self.__state > gst.STATE_NULL and
+ if (self.__state > Gst.State.NULL and
self.__adjustment.get_upper() == 0.0):
- try:
- duration = self.player.query_duration(gst.FORMAT_TIME, None)
- if duration[0] != -1:
- self.__adjustment.set_upper(duration[0] / 1000000000)
- except Exception:
- pass
-
- if self.__state == gst.STATE_PLAYING:
- self.__play_pause_image.set_from_stock(gtk.STOCK_MEDIA_PAUSE,
- gtk.ICON_SIZE_BUTTON)
+ success, duration = self.player.query_duration(Gst.Format.TIME)
+ if success:
+ self.__adjustment.set_upper(duration / 1000000000)
+
+ if self.__state == Gst.State.PLAYING:
+ self.__play_pause_image.set_from_stock(Gtk.STOCK_MEDIA_PAUSE,
+ Gtk.IconSize.BUTTON)
if self.__update_pos_id == 0:
- self.__update_pos_id = glib.timeout_add(500,
+ self.__update_pos_id = GLib.timeout_add(500,
self.__update_pos,
None)
else:
- self.__play_pause_image.set_from_stock(gtk.STOCK_MEDIA_PLAY,
- gtk.ICON_SIZE_BUTTON)
+ self.__play_pause_image.set_from_stock(Gtk.STOCK_MEDIA_PLAY,
+ Gtk.IconSize.BUTTON)
if self.__update_pos_id != 0:
- glib.source_remove(self.__update_pos_id)
+ GLib.source_remove(self.__update_pos_id)
self.__update_pos_id = 0
def gs_message_cb(self, bus, message):
- if message.type == gst.MESSAGE_EOS or message.type == gst.MESSAGE_ERROR:
+ if message.type == Gst.MessageType.EOS or message.type == Gst.MessageType.ERROR:
self.__seek(0)
- self.player.set_state(gst.STATE_PAUSED)
- elif message.type == gst.MESSAGE_STATE_CHANGED:
+ self.player.set_state(Gst.State.PAUSED)
+ elif message.type == Gst.MessageType.STATE_CHANGED:
(old, state, pending) = message.parse_state_changed()
self.__update_ui (state)
- elif message.type == gst.MESSAGE_ASYNC_DONE:
+ elif message.type == Gst.MessageType.ASYNC_DONE:
self.__update_pos()
class PlayWindowAudio(GStreamerWindow):
@@ -224,28 +224,32 @@ class PlayWindowAudio(GStreamerWindow):
try:
image = image_from_file(album_art_url)
self.__image = image.get_pixbuf()
- self.drawing_area.connect("expose-event", self.__draw)
+ self.drawing_area.connect("draw", self.__draw)
except Exception:
pass
- def __draw(self, area, event):
- self.draw_image(self.__image)
+ def __draw(self, widget, context):
+ if self.__image:
+ self.draw_image(self.__image, context)
return True
class PlayWindowVideo(GStreamerWindow):
+ def __on_realize(self, widget):
+ self.__xid = self.drawing_area.get_property('window').get_xid()
+
def __init__(self, name, url, close_window):
GStreamerWindow.__init__(self, name, url, close_window)
+ # get window XID when widget is realized
+ self.__xid = None
+ self.drawing_area.connect ("realize", self.__on_realize)
+
gsbus = self.player.get_bus()
gsbus.enable_sync_message_emission()
gsbus.connect("sync-message::element", self.gs_sync_message_cb)
-
def gs_sync_message_cb(self, bus, message):
- if message.structure != None and (message.structure.get_name() ==
- "prepare-xwindow-id"):
+ if message.get_structure().get_name() == "prepare-window-handle":
message.src.set_property("force-aspect-ratio", True)
- gtk.gdk.threads_enter()
- message.src.set_xwindow_id(self.drawing_area.window.xid)
- gtk.gdk.threads_leave()
+ message.src.set_window_handle(self.__xid)