Play Audio File Using Qt Mobility: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
(Sub-categorize)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''English''' [[Play Audio File Using Qt Mobility Bulgarian|Български]]


=Play Audio File Using Qt Mobility=


==Overview==
[[Category:HowTo]]
[[Category:Snippets::Misc]]


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.
{{LangSwitch}}


==Project Configuration==
== Overview ==
 
This article shows how to play audio file using [http://doc.qt.io/qt-5/qmediaplayer.html QMediaPlayer] 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>
CONFIG += mobility
MOBILITY+= multimedia
</code>
 
== Source Code ==


* .h
* .h  


Include required headers:<br />
Include required headers:
<code>
#include <QMediaPlayer>
</code>


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


* .cpp
private:


Play a file located on the device:<br />
QMediaPlayer '''m_pPlayer;
</code>


Implement the declared slot:<br />
''' .cpp


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


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

Latest revision as of 12:05, 28 November 2016


En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

Overview

This article shows how to play audio file using QMediaPlayer from Qt Mobility 1.1.

Project Configuration

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

CONFIG += mobility
MOBILITY+= multimedia

Source Code

  • .h

Include required headers:

#include <QMediaPlayer>

Declare slot and private members:

private slots:
 void statusChanged(QMediaPlayer::MediaStatus status);

private:

QMediaPlayer '''m_pPlayer;

.cpp

Play a file located on the device:

m_pPlayer = new QMediaPlayer(this);
connect(m_pPlayer, SIGNAL (positionChanged(qint64)), this, SLOT (statusChanged(qint64)));
//Select a file
m_pPlayer->setMedia(QUrl::fromLocalFile("e:SoundsDigitalGirl_Rules.mp3"));
//Set the volume
m_pPlayer->setVolume(50);
m_pPlayer->play();

Implement the declared slot: void MainWindow::statusChanged(QMediaPlayer::MediaStatus status) {

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

}