Phonon minimum needs to play a video: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
='''Phonon''' minimum needs to play a video.=
[[Category:Snippets]]


The [http://doc.qt.nokia.com/4.7/phonon-overview.html#phonon-overview documentation about Phonon] ''[doc.qt.nokia.com]'' 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.
= '''Phonon''' minimum needs to play a video. =


Before you start testing, make sure that you have the right programs and or libs installed on your computer. Look [http://doc.qt.nokia.com/4.7/phonon-overview.html#installing-phonon here] ''[doc.qt.nokia.com]'' for the setup you need.
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.


You need only 4 items to get a video to play.
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 to have a [http://doc.qt.nokia.com/4.7/phonon-mediaobject.html Phonon::MediaObject] ''[doc.qt.nokia.com]''
You need only 4 items to get a video to play.<br /># You need to have a &quot;Phonon::MediaObject&amp;quot;:http://doc.qt.nokia.com/4.7/phonon-mediaobject.html<br /># You need to have a &quot;Phonon::VideoWidget&amp;quot;:http://doc.qt.nokia.com/4.7/phonon-videowidget.html<br /># You need to have a &quot;Phonon::AudioOutput&amp;quot;:http://doc.qt.nokia.com/4.7/phonon-audiooutput.html<br /># add your .pro file with &quot;+= phonon&amp;quot;
# You need to have a [http://doc.qt.nokia.com/4.7/phonon-videowidget.html Phonon::VideoWidget] ''[doc.qt.nokia.com]''
# You need to have a [http://doc.qt.nokia.com/4.7/phonon-audiooutput.html Phonon::AudioOutput] ''[doc.qt.nokia.com]''
# add your .pro file with += phonon”


Then the code:
Then the code:


That’s all there is.
<code><br />//include the right lib:<br />#include &lt;phonon&amp;gt;


* '''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.
// setup the objects:<br />Phonon::MediaObject *obj_MediaObject = new Phonon::MediaObject(this);<br />Phonon::VideoWidget *wid_videoWidget = new Phonon::VideoWidget(this);<br />Phonon::AudioOutput '''aio_audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory,this);
<br />//clear the mediaobject:<br />obj_MediaObject-&gt;clearQueue();
<br />//Put a video in the queue:<br />obj_MediaObject-&gt;enqueue(Phonon::MediaSource(&quot;path to video&amp;quot;));
<br />//make the proper connections:<br />Phonon::createPath(obj_MediaObject, wid_videoWidget); // to link the mediaobject with the video widget.<br />Phonon::createPath(obj_MediaObject, aio_audioOutput); // to link the mediaobject with audio output.
<br />//play the video:<br />obj_MediaObject-&gt;play();<br /></code>
<br />That's all there is.
<br />''' '''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.
 
===Categories:===
 
* [[:Category:snippets|snippets]]

Revision as of 10:52, 24 February 2015


Phonon minimum needs to play a video.

The "documentation about Phonon&quot;:http://doc.qt.nokia.com/4.7/phonon-overview.html#phonon-overview provided by Qt doesn't give you an "out of the box&quot; 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&quot;: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&quot;:http://doc.qt.nokia.com/4.7/phonon-mediaobject.html
# You need to have a "Phonon::VideoWidget&quot;:http://doc.qt.nokia.com/4.7/phonon-videowidget.html
# You need to have a "Phonon::AudioOutput&quot;:http://doc.qt.nokia.com/4.7/phonon-audiooutput.html
# add your .pro file with "+= phonon&quot;

Then the code:

<br />//include the right lib:<br />#include &lt;phonon&amp;gt;

// setup the objects:<br />Phonon::MediaObject *obj_MediaObject = new Phonon::MediaObject(this);<br />Phonon::VideoWidget *wid_videoWidget = new Phonon::VideoWidget(this);<br />Phonon::AudioOutput '''aio_audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory,this);
<br />//clear the mediaobject:<br />obj_MediaObject-&gt;clearQueue();
<br />//Put a video in the queue:<br />obj_MediaObject-&gt;enqueue(Phonon::MediaSource(&quot;path to video&amp;quot;));
<br />//make the proper connections:<br />Phonon::createPath(obj_MediaObject, wid_videoWidget); // to link the mediaobject with the video widget.<br />Phonon::createPath(obj_MediaObject, aio_audioOutput); // to link the mediaobject with audio output.
<br />//play the video:<br />obj_MediaObject-&gt;play();<br />


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.