I want to do an mp4 player and I am trying to get the module to play a video but at the moment of giving it no error occurs
def prueba(self,z):
self.open = wx.media.MediaCtrl(panel)
self.open.Load("video.mp4")
self.open.GetBestSize()
self.open.Play()
panel = wx.Panel(frame,id=-1,size=(500,500))
self.Bind(wx.media.EVT_MEDIA_LOADED,self.prueba)
Edit:
When I´m trying the following code:
import wx
import wx.media
class TestPanel(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.testMedia = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER,)
self.media = '/home/rolf/BBB.ogv'
self.testMedia.Bind(wx.media.EVT_MEDIA_LOADED, self.play)
self.testMedia.Bind(wx.media.EVT_MEDIA_FINISHED, self.quit)
if self.testMedia.Load(self.media):
pass
else:
print("Media not found")
self.quit(None)
def play(self, event):
self.testMedia.Play()
def quit(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.App()
Frame = TestPanel()
Frame.Show()
app.MainLoop()
With an mp4 file...
ERROR
You need to load the media before the event EVT_MEDIA_LOADED will fire.
Try this as a skeleton program:
import wx
import wx.media
class TestPanel(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.testMedia = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER,)
self.media = '/home/rolf/BBB.ogv'
self.testMedia.Bind(wx.media.EVT_MEDIA_LOADED, self.play)
self.testMedia.Bind(wx.media.EVT_MEDIA_FINISHED, self.quit)
if self.testMedia.Load(self.media):
pass
else:
print("Media not found")
self.quit(None)
def play(self, event):
self.testMedia.Play()
def quit(self, event):
self.Destroy()
if __name__ == '__main__':
app = wx.App()
Frame = TestPanel()
Frame.Show()
app.MainLoop()
Edit based on comment
The above code works on Linux.
If you are using a different OS or if you are on Linux but do not have Gstreamer installed, you may have an issue.
There is an option to choose your media backend:
Generally, you should almost certainly leave this part up to wx.media.MediaCtrl - but if you need a certain backend for a particular reason, such as QuickTime for playing .mov files, all you need to do to choose a specific backend is to pass the name of the backend class to wx.media.MediaCtrl.Create . The following are valid backend identifiers:
MEDIABACKEND_DIRECTSHOW: Use ActiveMovie/DirectShow. Uses the native ActiveMovie (I.E. DirectShow) control. Default backend on Windows and supported by nearly all Windows versions, even some Windows CE versions. May display a windows media player logo while inactive.
MEDIABACKEND_QUICKTIME: Use QuickTime. Mac Only. WARNING: May not working correctly embedded in a wx.Notebook.
MEDIABACKEND_GSTREAMER, Use GStreamer. Unix Only. Requires GStreamer 0.8 along with at the very least the xvimagesink, xoverlay, and gst-play modules of gstreamer to function. You need the correct modules to play the relevant files, for example the mad module to play mp3s, etc.
MEDIABACKEND_WMP10, Uses Windows Media Player 10 (Windows only) - works on mobile machines with Windows Media Player 10 and desktop machines with either Windows Media Player 9 or 10.
This would result in your media defintion looking like this:
self.testMedia = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER,szBackend=wx.media.MEDIABACKEND_WMP10)
for example.
Related
Hello I am writing python application with gtk and vlc. Playback works, but without hardware acceleration.
import vlc
class Player:
def __init__(self):
self.instance = vlc.Instance("--no-xlib")
self.player = self.instance.media_player_new()
def visualize(self,widget):
self.player.set_xwindow(widget.get_window().get_xid())
def playurl(self,url):
media = self.instance.media_new(url)
self.player.set_media(media)
self.player.play()
When I run it I see:
[00007f4dfc014830] main filter error: Failed to create video converter
[00007f4df80af2a0] vdpau_avcodec generic error: Xlib is required for VDPAU
So I decided to remove "--no-xlib" parameter, but now I see this:
[00007f16b40078f0] egl_x11 gl error: Xlib not initialized for threads
Someone said this can help:
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
I've added this on start of my main function. But it causes segmentation fault when calling Gtk.main()
def main():
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
builder = Gtk.Builder()
builder.add_from_file(BUILDER_PATH)
mw = MainWin(builder) # class containing widgets loaded from GtkBuilder
mw.Show()
myvlc = Player()
myvlc.visualize(mw.player) # mw.player is GtkDrawingArea
myvlc.playurl("http://livesim.dashif.org/livesim/ato_10/testpic_2s/Manifest.mpd")
Gtk.main() # Crash
if __name__ == "__main__":
main()
PS: When I start vlc player /usr/bin/vlc HW acceleration works normally.
I want to dive in Python by building a simple browser-application. I've mad a minimalistic webkitbrowser with a tutorial and now want to extend the program, but I'm stuck at some tiny problems I cannot solve.
Python 3.3.3
using Glade for the UI
The first step is to simply add a second scrolledWindow in which the developer-tools should load, immediately.
Here is my .ui-file so far, and this is the python-code:
from gi.repository import Gtk, WebKit
UI_FILE = "browser.ui"
class Browser:
"""A simple Webkit-Browser in GTK+"""
def __init__(self):
self.builder = Gtk.Builder()
self.builder.add_from_file(UI_FILE)
self.builder.connect_signals(self)
self.back = self.builder.get_object("back")
self.forward = self.builder.get_object("forward")
self.adress = self.builder.get_object("adress")
self.webview = WebKit.WebView()
scrolled_window = self.builder.get_object("scrolledwindow")
scrolled_window.add(self.webview)
self.settings = WebKit.WebSettings()
self.settings.set_property('enable-developer-extras', True)
self.webview.set_settings(self.settings)
self.devtools = WebKit.WebInspector()
scrolled_window_dev = self.builder.get_object("scrolledwindowDev")
scrolled_window_dev.add(self.devtools)
^^^^^
self.webview.connect("title-changed", self.on_title_changed)
self.window = self.builder.get_object("window")
self.window.show_all()
def on_title_changed(self, webview, frame, title):
self.window.set_title(title)
def on_button_clicked(self, button):
if button.get_stock_id() == Gtk.STOCK_GO_FORWARD:
self.webview.go_forward()
elif button.get_stock_id() == Gtk.STOCK_GO_BACK:
self.webview.go_back()
def on_entry_activate(self, widget):
url = widget.get_text()
if not "http://" in url:
url = "http://"+url
self.webview.load_uri(url)
def destroy(self, window):
Gtk.main_quit()
def main():
app = Browser()
Gtk.main()
if __name__ == "__main__":
main()
I get the error
TypeError: argument widget: Expected Gtk.Widget, but got
gi.repository.WebKit.WebInspector
Okay, this is stated in the reference of Webkit, that WebInspector is a GObject and not a GtkWidget. But I don't know what to do now.
So, can I make a GtkWidget from a GObject (if yes - how) or should I attach the dev-tools in a complete different way?
The inspector, as you noted, isn't a widget. It's a web page, so you need to create another webview for it. You do this by getting self.window.props.web_inspector (don't create a new inspector) and connecting to its inspect-web-view signal. Inside that signal handler, you need to create a new webview, add that webview to a window or wherever you want to display it, and return it.
You'll probably also want to handle the show-window, attach-window, detach-window, and close-window signals.
More documentation here: inspect-web-view
Example of running Inspector in separate window. Webkit-gtk.
This gist without many signals connected.
https://gist.github.com/alex-eri/53518825b2a8a50dd1695c69ee5058cc
I wrote a simple video player using Phonon in PyQt4. The videos are playing fine. But I am unable to seek the video to given position. This the code I've written:
#!/usr/bin/python
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.phonon import Phonon
import sys
class VideoPlayer(QWidget):
def __init__(self, address, parent = None):
self.address = address
QWidget.__init__(self)
self.player = Phonon.VideoPlayer(Phonon.VideoCategory, self)
self.player.load(Phonon.MediaSource(self.address))
window = QHBoxLayout(self)
window.addWidget(self.player)
self.setWindowTitle("Simple Video Player")
self.player.play()
self.player.seek(10240)
app = QApplication(sys.argv)
vp = VideoPlayer(sys.argv[1])
vp.show()
app.exec_()
All I am trying to do is to start and stop a video at given positions.
Thanks in advance.
It is not possible to seek to a position in a media source whilst it is still loading.
So connect a handler to the media object's stateChanged signal, and wait until it's state changes to PlayingState before attempting to seek.
self.player.mediaObject().stateChanged.connect(self.handleStateChanged)
...
def handleStateChanged(self, newstate, oldstate):
if newstate == Phonon.PlayingState:
self.player.seek(10240)
Some media isn't easily seekable by Phonon. The documentation says
Note that the backend is free to ignore the seek request if the media source isn't seekable; you can check this by asking the media object of the VideoPlayer.
player->mediaObject()->isSeekable();
My guess is that your video isn't seekable.
What media are you using? Things like streaming video (for example), generally aren't seekable.
I want to start playing a .wmv file as soon as it is loaded in wxPython. I wrote a small code for it. The code does not give any error, but it does not show any video as well, but the sound does play in the background. It just shows a gray screen. Following is the code I wrote for my program.
import wx
import wx.media
class TestPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1, style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN)
# Create some controls
try:
self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER)
except NotImplementedError:
self.Destroy()
raise
self.mc.Load(r"C:\Documents and Settings\N1002401B\Desktop\test1.wmv")
#self.slider.SetRange(0, self.mc.Length())
#folder, filename = os.path.split("C:\Documents and Settings\N1002401B\Desktop\test1.wmv")
self.Bind(wx.media.EVT_MEDIA_LOADED, self.OnPlay)
def OnPlay(self,evt):
self.mc.Play()
app = wx.App(0)
frame = wx.Frame(None)
panel = TestPanel(frame)
frame.Show()
app.MainLoop()
I am using Python 2.7 and windows XP.
Can anyone please help me on this one. I would be really grateful for your help.
I have a PyGTK program which is hidden most of the time, but with a keypress it shall come up as a popup. Therefore I want the program not to be activated when its opened. I tried several options to to that, with no success:
self.window.show()
self.window.set_focus(None)
Activates the program, but sets no focus.
self.window.set_accept_focus(False)
self.window.show()
self.window.set_accept_focus(True)
With the last command, the window gets activated.
self.window.show()
self.window.unset_flags(gtk.HAS_FOCUS)
Does nothing...
Btw. I am using Ubuntu 9.10 (metacity)
Build the window but don't call show() on it until it is ready to be activated. Then use self.window.present().
EDIT:
If you never want the window to be activated, why not try a notification popup? You need libnotify for this. There are Python bindings. Here is an example: http://roscidus.com/desktop/node/336
In combination with a toolbar applet, this could do what you want -- i.e. the notification is raised when the user either clicks on the applet or presses the key combination.
I figured out how to do it. See the example below:
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import gobject
class HelloWorld:
window=None
def hello(self, widget, data=None, data2=None):
HelloWorld.window.set_accept_focus(True)
HelloWorld.window.present()
def __init__(self):
HelloWorld.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.button = gtk.Entry(50)
self.button.connect("focus-in-event", self.hello, None)
HelloWorld.window.add(self.button)
self.button.show()
HelloWorld.window.set_accept_focus(False)
self.button.connect('button-press-event', self.hello)
HelloWorld.window.show()
def main(self):
gtk.main()
if __name__ == "__main__":
hello = HelloWorld()
hello.main()