Play Audio File Using Qt Mobility: Difference between revisions
Jump to navigation
Jump to search
AutoSpider (talk | contribs) (Decode HTML entity names) |
Henri Vikki (talk | contribs) (Doc link & format) |
||
Line 1: | Line 1: | ||
[[Category:HowTo]] | [[Category:HowTo]] | ||
Line 6: | Line 6: | ||
'''English''' [[Play_Audio_File_Using_Qt_Mobility_Bulgarian|Български]] | '''English''' [[Play_Audio_File_Using_Qt_Mobility_Bulgarian|Български]] | ||
== Overview == | == Overview == | ||
This article shows how to play audio file using [http://doc.qt. | 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 == | == Project Configuration == | ||
Line 17: | Line 17: | ||
<code> | <code> | ||
CONFIG | CONFIG += mobility | ||
MOBILITY | MOBILITY+= multimedia | ||
</code> | </code> | ||
Revision as of 06:45, 13 April 2015
English Български
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();
}
}