Play Audio File Using Qt Mobility

From Qt Wiki
Jump to navigation Jump to search

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


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);


QMediaPlayer '''m_pPlayer;


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
//Set the volume

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

if ( (QMediaPlayer::LoadedMedia == status) && m_pPlayer)