The wiki is in the process of moving to Please make your edits there.

Phonon_minimum_needs_to_play_a_video | Qt Wiki | Qt Project

Phonon minimum needs to play a video.

The documentation about Phonon [] provided by Qt doesn’t give you an “out of the box” explanation on how to play a video using Phonon in Qt. That’s why I write this down in order to help a little.

Before you start testing, make sure that you have the right programs and or libs installed on your computer. Look here [] for the setup you need.

You need only 4 items to get a video to play.

  1. You need to have a Phonon::MediaObject []
  2. You need to have a Phonon::VideoWidget []
  3. You need to have a Phonon::AudioOutput []
  4. add your .pro file with “+= phonon”

Then the code:

  1. //include the right lib:
  2. #include <phonon>  
  4. // setup the objects:
  5. Phonon::MediaObject *obj_MediaObject = new Phonon::MediaObject(this);
  6. Phonon::VideoWidget *wid_videoWidget = new Phonon::VideoWidget(this);
  7. Phonon::AudioOutput *aio_audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory,this);
  9. //clear the mediaobject:
  10. obj_MediaObject->clearQueue();
  12. //Put a video in the queue:
  13. obj_MediaObject->enqueue(Phonon::MediaSource("path to video"));
  15. //make the proper connections:
  16. Phonon::createPath(obj_MediaObject, wid_videoWidget); // to link the mediaobject with the video widget.
  17. Phonon::createPath(obj_MediaObject, aio_audioOutput); // to link the mediaobject with audio output.
  19. //play the video:
  20. obj_MediaObject->play();

That’s all there is.

  • Note: This code only works on local video files. I didn’t have YouTube videos and mms streaming working yet. When I do, I will edit this page.

It’s off course also possible for others to edit a working code.