Playing audio in QML
-
I am trying to create a JukeBox program. I have started by trying to play audio in QML. I am using phonon module to create a class that is able to play an audio file and then I have registered this in QML. I am obviously making a fundamental error as I get following issues when trying to run it:
error: symbol(s) not found for architecture x86_64
error: collect2: ld returned 1 exit statushere is my code, there is not much to it:
in JukeBox.pro I added
@QT += core gui phonon declarative@
qmlaudio.h
@#ifndef QMLAUDIO_H
#define QMLAUDIO_H#include <phonon>
#include <QDeclarativeItem>
#include <QUrl>class QmlAudio : public QDeclarativeItem
{
Q_OBJECT
public:
QmlAudio(QDeclarativeItem *parent = 0);public slots:
void setSong(const QUrl & songUrl);
void play();private:
Phonon::MediaObject *audioObject;
};
#endif // QMLAUDIO_H
@qmlaudio.cpp
@#include "qmlaudio.h"
#include <QObject>
#include <phonon>QmlAudio::QmlAudio(QDeclarativeItem *parent) : QDeclarativeItem(parent)
{audioObject = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource("/Users/jankokajtez/My Docs/Qt Projects/JukeBox/qml/JukeBox/song.mp3"));
}
void QmlAudio::setSong(const QUrl & songUrl)
{
audioObject->setCurrentSource(Phonon::MediaSource(songUrl));
}void QmlAudio::play()
{
audioObject->play();
}
@main.cpp
@#include <QtGui/QApplication>
#include <QtDeclarative>
#include "qmlaudio.h"Q_DECL_EXPORT int main(int argc, char *argv[])
{
QApplication app(argc, argv);QDeclarativeView viewer; qmlRegisterType<QmlAudio>("qmlAudio", 1, 0, "QmlAudio"); viewer.setSource(QUrl("/Users/jankokajtez/My Docs/Qt Projects/JukeBox/qml/JukeBox/main.qml")); viewer.show(); return app.exec();
}@
main.qml
@import QtQuick 1.0
import qmlAudio 1.0Rectangle{
id: mainScreen
height: 900
color: "#363636"
width: 1440QmlAudio{ id: song; } Text { id: playButton x: 394 y: 482 width: 85 height: 67 text: qsTr("PLAY") font.pixelSize: 30 anchors.centerIn: parent MouseArea{ id:playButtonMouseArea anchors.fill: parent onClicked: song.play() } }
}@
-
People here have a similar issue(though not with playing audio), but yes error messages are same:
http://developer.qt.nokia.com/forums/viewthread/6924
Are there any more compiler generated statements btw, if yes try pasting it here.