I’ve been searching for a while and haven’t come up with any results yet. I’m trying to do something that I imagine should be fairly simple, but have yet to see a potential solution. My eventual goal is to be able to incorporate a video player into a Maya PyQt interface. I’m new to PyQt, and from what I’ve gathered the way to approach something like this is using the Phonon module.
To start with, I’ve been trying to get an interface to play a simple song, since examples of simple audio players using this module seem to abound. Everything seems to work and the window launches just fine, but I’m getting no sound. I was curious whether anyone else has attempted to get a video or music to play in Maya. If the Phonon module is not the proper approach, I’d appreciate any advice on the subject.
As I said, I’m very new to PyQt, and it wouldn’t surprise me that I have made a very simple error.
My code is as follows:
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4.phonon import Phonon
import sip
import maya.OpenMayaUI as omu
def maya_main_window():
ptr = omu.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QtCore.QObject)
class My_Player(QtGui.QMainWindow):
def __init__(self, parent = maya_main_window()):
QtGui.QMainWindow.__init__(self, parent)
self.setWindowTitle("My Player")
self.playsong()
def playsong(self):
m_media = Phonon.MediaObject()
output = Phonon.AudioOutput(Phonon.MusicCategory)
Phonon.createPath(m_media, output)
m_media.setCurrentSource(Phonon.MediaSource("C:/Users/Ben/Documents/media.mp3"))
m_media.play()
win = My_Player()
try:
win.close()
except:
pass
win.show()
I’ve got video playback via phonon working in maya before. It’s not quite as simple as you might first think.
The most likely reason it won’t work for you at the moment is that Maya does not include the phonon backend library. You’ll need to build a version of Qt compatible with your Maya version and enable building the appropriate phonon-backend for your system in the build options to get that. There are also some system specific requirements to allow Qt to build the appropriate backend (e.g. on windows you’ll need the DirectX SDK installed). You then need to put the phonon-backend plugin library somewhere that Qt in Maya can load it. This can be done either by putting the file directly into the Qt plugins folder in the maya install path or by adding a Qt plugin search path at runtime before you try to initialise phonon.
If you have trouble doing that I can probably write up some more detailed instructions on what you need to do when I’m back at my work machine.
Thanks for your reply. I’ll look into following your instructions, and I’ll get back if I can’t figure it out.
I really appreciate the help.
It was probably optimistic of me to think that I could get this working. I’ve actually been having trouble building Qt for the last several days. I only ever got it to actually work in Maya via a pre-built PyQt4 download very graciously provided by Nathan Horne. I’ve been trying to follow the instructions for installing PyQt, but the Autodesk documentation is woefully pathetic, and I’ve found so many conflicting instructions on a variety of blogs that I’m more lost than ever with all the information.
As I said, I’m still very new to this, and unfortunately the process still seems somewhat mystical to me. If you could take the time to write those detailed instructions you mentioned, I would be very grateful. I’ll continue to experiment and search for solutions in the meantime.
UPDATE
I think I’ve run into just about every problem possible, but I believe I’ve got the correct phonon-backends. It’s hard for me to verify, since it’s difficult to pinpoint where the problem could potentially be, either in my code, builds, or file structure. I installed the DirectX SDK and compiled Maya 2013’s Qt backend. The compile executed without any errors, as far as I could tell. I now have a folder in the plugins folder of Qt called phonon-backends. I’m not sure how to verify that it incorporated the DirectX SDK. I set a variable directing it to the DirectX env before running the configure command. I’ve moved the phonon-backend folder into C:\Program Files\Autodesk\Maya2013\qt-plugins, which seems to be where you directed I should place it. I still cannot get Phonon to produce any sound or video.
If you cannot tell from the above, much of what I’ve been doing is trial and error, and my experience is not extensive enough to be sure that I’m performing the correct sequences of actions. I can be much more explicit about my steps if that is necessary.
UPDATE 2
I actually have been getting the video to play. The problem seems to have been that it will only play WMV and AVI files. From what I can find, this seems to indicate that it’s using Windows Media Player as the backend. I’m still trying to get it to play MP4 and MOV, but this is definitely a good start. I’m going to do a couple of tests to see whether or not I even needed to add those phonon-backend files, or which location it was necessary to put them.
UPDATE 3
Having the phonon-backends installed in the qt-plugins folder is most definitely necessary, and seems to be the only place where it’s needed. Now I just need to figure out why I can’t play any other file video types besides the two I mentioned earlier. I have gotten it to play certain mp3 files, but not all of them.
Sounds like you’re pretty much there. Trial and error is a good way to learn anyway if you’ve got the time. Yep, the phonon-backend just needs to be built and then you can place it in the Maya20XX\qt-plugins folder and it will load fine from there (I load it from an external directory in my tools setup to keep the Maya install clean but this probably isn’t necessary in your case).
In response to your queries in your initial Update, I believe everything built fine. If the Qt build can’t find the stuff it requires to build the phonon-backend (e.g. the DirectX SDK) then it just won’t build it at all so if it’s there it should be fine.
The issue you’re having with only playing some files sounds like it’s just a case of missing codecs now. Sounds like your Qt and phonon-backend is working correctly as far as I can tell. On windows I believe phonon uses directshow as the backend so you’ll need directshow codecs to support each of the formats you’re trying to play. One way you could test if this is the problem is to install a direct show codec pack e.g. the K-Lite Codec Pack and check if your video/audio works after that. If you need to distribute your tools it gets a bit more tricky obviously but that’s a way to test anyway.
Installing the K-Lite Codec pack seems to be the accepted solution to this problem, based on what I’ve found and what you’ve mentioned.
However, installing it hasn’t seemed to have made any difference at all. The same things as before are playable. Could there be some kind of settings or connections I have to adjust/make before they will work?
Hmmm that’s interesting. No, as far as I know there’s nothing else you explicitly need to set up. That codec pack handles the vast majority of formats so I’d have expected something to change (possibly requires a restart?). Which formats/encodings are you not able to play exactly? Also, do the files you’re unable to play with phonon open correctly in Media Player Classic (which would have been installed with the codec pack)?
I’m at a bit of a loss as well. Most of the answers I’ve found also say that installing the K-Lite pack should have worked. I’ve found a few places where people have mentioned that it didn’t correct their issues, but most have received no response beyond that.
To answer your questions: restarting didn’t seem to make any difference, and I need for phonon to at least be capable of playing MP4 and MOV.
Both of those formats (and many others) are working in the Media Player Classic.
That leads me to believe that the codecs are working correctly. Do you know of what else could be the cause?
When I did it it seemed to pick up the directshow codecs and play any encodings supported by them, so I’m pretty much just guessing at this stage. I wonder whether it’s trying to use 64bit codecs instead of 32 for some reason (possibly an unusual build configuration?). The regular K-lite codec pack is all 32bit codecs but there is a 64 bit version which it might be worth trying to see if it changes anything.
It might also be useful to try this to find out which mime types the backend thinks it has support for:
from PyQt4.phonon import Phonon
supported = Phonon.BackendCapabilities.availableMimeTypes()
for s in supported:
print s
Also, just to check, in your Maya20XX\qt-plugins\phonon_backend folder you’ve just got phonon_ds94.dll and nothing else?
You’re a lifesaver. As soon as I installed the 64-bit K-Lite codec package, everything clicked into place and now works like a charm. I wouldn’t have gotten this far without you pointing me in the right direction, so thank you for your help.
One thing that worries me is, like you said, what happens when it comes time to distributing tools. As far as I can see right now, what I have will only work on a Windows 7, 64-bit Maya 2013 system. That’s getting a bit specific. And then they’ll need the codecs I installed. Is it different in a studio environment where it may be possible to standardize everyone’s system, or it is necessary to, for instance, build PyQt and backends for different variations and point to them with PYTHONPATH? It almost makes me wonder about the feasibility of using code based on PyQt, since I can definitely see problems getting it out to everyone.
From what you’ve said, it sounds like you might have had some experience with this, and I’d be curious to know what you learned.
Regardless though, thank you for the help you’ve already provided. I’m ecstatic that I’ve got this working.
Good stuff, glad you got it working. Like I said, it’s not quite as simple as it might first appear :P.
What you’ve got now I think should work on any recent windows systems (not just 7). But yes, the stuff you’ve built will be pretty specific to the Maya version you compiled it for (it’s possible the phonon_backend dll would work with other versions especially if they use a similar version of Qt but you shouldn’t bank on that). Distributing tools dependant on PyQt/PySide has been a hassle so far because your users need to have it on their system. And yes, that can mean multiple versions of PyQt/PySide and multiple plugin version for each version of Maya you’re supporting (for an in-house toolset you generally need a mechanism for doing this at some point anyway though e.g. for maya mll plugins). Since PySide is shipping with Maya 2014 I’d guess we’ll see more tools using that being released into the wilds of the internet in future.
FYI if you want to specify a path to your phonon_backend at runtime then in PyQt you need to use:
PyQt4.QtGui.QApplication.addLibraryPath(MY_PATH)
rather than PYTHONPATH (it’s a dll loaded by Maya’s internal Qt not anything python related).
Tools deployment is a bit of a topic of its own though and the best way to do it will depend a lot on who you’re making them for and what your requirements are. Between studios it can vary quite a bit. Generally it’ll involve some pre-launch modification of environment variables (e.g. PYTHONPATH, MAYA_PLUG_IN_PATH etc.) which can be done in a number of ways (launcher app/script, system environment variable (generally a bad idea), maya.env etc.) and there may initially be an installer to set up that process and/or install dependencies (e.g. codecs in your case).
There have been a few threads discussing tools deployment on here before that might help point you in the right direction e.g.: Best Way to Share Your Scripts? - Coding - Tech-Artists.Org