Phonon minimum needs to play a video: Difference between revisions
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
= '''Phonon''' minimum needs to play a video. = | = '''Phonon''' minimum needs to play a video. = | ||
The | The "documentation about Phonon":http://doc.qt.nokia.com/4.7/phonon-overview.html#phonon-overview 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 | Before you start testing, make sure that you have the right programs and or libs installed on your computer. Look "here":http://doc.qt.nokia.com/4.7/phonon-overview.html#installing-phonon for the setup you need. | ||
You need only 4 items to get a video to play. | You need only 4 items to get a video to play. | ||
# You need to have a "Phonon::MediaObject":http://doc.qt.nokia.com/4.7/phonon-mediaobject.html | |||
# You need to have a "Phonon::VideoWidget":http://doc.qt.nokia.com/4.7/phonon-videowidget.html | |||
# You need to have a "Phonon::AudioOutput":http://doc.qt.nokia.com/4.7/phonon-audiooutput.html | |||
# add your .pro file with "+= phonon" | |||
Then the code: | Then the code: | ||
<code> | <code> | ||
//include the right lib: | |||
#include <phonon> | |||
// setup the objects: | // setup the objects: | ||
Phonon::MediaObject *obj_MediaObject = new Phonon::MediaObject(this); | |||
Phonon::VideoWidget *wid_videoWidget = new Phonon::VideoWidget(this); | |||
Phonon::AudioOutput '''aio_audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory,this); | |||
//clear the mediaobject: | |||
obj_MediaObject->clearQueue(); | |||
//Put a video in the queue: | |||
obj_MediaObject->enqueue(Phonon::MediaSource("path to video")); | |||
//make the proper connections: | |||
Phonon::createPath(obj_MediaObject, wid_videoWidget); // to link the mediaobject with the video widget. | |||
Phonon::createPath(obj_MediaObject, aio_audioOutput); // to link the mediaobject with audio output. | |||
//play the video: | |||
obj_MediaObject->play(); | |||
</code> | |||
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. | It's off course also possible for others to edit a working code. |
Revision as of 11:12, 25 February 2015
Phonon minimum needs to play a video.
The "documentation about Phonon":http://doc.qt.nokia.com/4.7/phonon-overview.html#phonon-overview 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":http://doc.qt.nokia.com/4.7/phonon-overview.html#installing-phonon for the setup you need.
You need only 4 items to get a video to play.
- You need to have a "Phonon::MediaObject":http://doc.qt.nokia.com/4.7/phonon-mediaobject.html
- You need to have a "Phonon::VideoWidget":http://doc.qt.nokia.com/4.7/phonon-videowidget.html
- You need to have a "Phonon::AudioOutput":http://doc.qt.nokia.com/4.7/phonon-audiooutput.html
- add your .pro file with "+= phonon"
Then the code:
//include the right lib:
#include <phonon>
// setup the objects:
Phonon::MediaObject *obj_MediaObject = new Phonon::MediaObject(this);
Phonon::VideoWidget *wid_videoWidget = new Phonon::VideoWidget(this);
Phonon::AudioOutput '''aio_audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory,this);
//clear the mediaobject:
obj_MediaObject->clearQueue();
//Put a video in the queue:
obj_MediaObject->enqueue(Phonon::MediaSource("path to video"));
//make the proper connections:
Phonon::createPath(obj_MediaObject, wid_videoWidget); // to link the mediaobject with the video widget.
Phonon::createPath(obj_MediaObject, aio_audioOutput); // to link the mediaobject with audio output.
//play the video:
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.