Play Audio File Using Qt Mobility: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
AutoSpider (talk | contribs) (Add "cleanup" tag) |
||
Line 1: | Line 1: | ||
{{Cleanup | reason=Auto-imported from ExpressionEngine.}} | |||
[[Category:HowTo]] | [[Category:HowTo]] | ||
[[Category:snippets]] | [[Category:snippets]] |
Revision as of 16:14, 3 March 2015
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine. Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean. |
English Български
Play Audio File Using Qt Mobility
Overview
This article shows how to play audio file using "QMediaPlayer":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:
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();
}
}