Play Audio File Using Qt Mobility: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
'''English''' [[Play Audio File Using Qt Mobility Bulgarian|Български]]
[[Category:HowTo]]<br />[[Category:snippets]]


=Play Audio File Using Qt Mobility=
'''English''' [[Play_Audio_File_Using_Qt_Mobility_Bulgarian|Български]]


==Overview==
= Play Audio File Using Qt Mobility =


This article shows how to play audio file using [http://doc.qt.nokia.com/qtmobility/qmediaplayer.html QMediaPlayer] ''[doc.qt.nokia.com]'' from Qt Mobility 1.1.
== Overview ==


==Project Configuration==
This article shows how to play audio file using &quot;QMediaPlayer&amp;quot;:http://doc.qt.nokia.com/qtmobility/qmediaplayer.html from Qt Mobility 1.1.
 
== Project Configuration ==


Modify the project configuration .pro file by including Qt Mobility support:
Modify the project configuration .pro file by including Qt Mobility support:


==Source Code==
<code><br />CONFIG ''= mobility<br />MOBILITY''= multimedia<br /></code>


* .h
== Source Code ==


Include required headers:<br />
* .h


Declare slot and private members:<br />
Include required headers:<br /><code><br />#include &lt;QMediaPlayer&amp;gt;<br /></code>


* .cpp
Declare slot and private members:<br /><code><br />private slots:<br /> void statusChanged(QMediaPlayer::MediaStatus status);


Play a file located on the device:<br />
private:


Implement the declared slot:<br />
QMediaPlayer '''m_pPlayer;<br /></code>
<br />''' .cpp


===Categories:===
Play a file located on the device:<br /><code><br />m_pPlayer = new QMediaPlayer(this);<br />connect(m_pPlayer, SIGNAL (positionChanged(qint64)), this, SLOT (statusChanged(qint64)));<br />//Select a file<br />m_pPlayer-&gt;setMedia(QUrl::fromLocalFile&amp;amp;#40;&quot;e:SoundsDigitalGirl_Rules.mp3&amp;quot;&amp;#41;);<br />//Set the volume<br />m_pPlayer-&gt;setVolume(50);<br />m_pPlayer-&gt;play();<br /></code>


* [[:Category:HowTo|HowTo]]
Implement the declared slot:<br /><code><br />void MainWindow::statusChanged(QMediaPlayer::MediaStatus status)<br />{<br /> if ( (QMediaPlayer::LoadedMedia == status) &amp;&amp; m_pPlayer)<br /> {<br /> m_pPlayer-&gt;play();<br /> }<br />}
* [[:Category:snippets|snippets]]

Revision as of 11:12, 24 February 2015


English Български

Play Audio File Using Qt Mobility

Overview

This article shows how to play audio file using "QMediaPlayer&quot;:http://doc.qt.nokia.com/qtmobility/qmediaplayer.html from Qt Mobility 1.1.

Project Configuration

Modify the project configuration .pro file by including Qt Mobility support:

<br />CONFIG ''= mobility<br />MOBILITY''= multimedia<br />

Source Code

  • .h

Include required headers:

<br />#include &lt;QMediaPlayer&amp;gt;<br />

Declare slot and private members:

<br />private slots:<br /> void statusChanged(QMediaPlayer::MediaStatus status);

private:

QMediaPlayer '''m_pPlayer;<br />


.cpp

Play a file located on the device:

<br />m_pPlayer = new QMediaPlayer(this);<br />connect(m_pPlayer, SIGNAL (positionChanged(qint64)), this, SLOT (statusChanged(qint64)));<br />//Select a file<br />m_pPlayer-&gt;setMedia(QUrl::fromLocalFile&amp;amp;#40;&quot;e:SoundsDigitalGirl_Rules.mp3&amp;quot;&amp;#41;);<br />//Set the volume<br />m_pPlayer-&gt;setVolume(50);<br />m_pPlayer-&gt;play();<br />

Implement the declared slot:

void MainWindow::statusChanged(QMediaPlayer::MediaStatus status)
{
if ( (QMediaPlayer::LoadedMedia == status) && m_pPlayer)
{
m_pPlayer->play();
}
}