Playing Sound with Ubuntu QML Toolkit preview

Problem solved, the answer is to use QtMultimedia 5.0, which now provides the Audio element.

http://qt-project.org/doc/qt-5.0/qtmultimedia/qml-qtmultimedia5-audio.html


Here's a quick example of how to play an mp3 file using MediaPlayer component from QtMultimedia and the Ubuntu UI toolkit:

import QtQuick 2.0
import Ubuntu.Components 0.1
import QtMultimedia 5.0

MainView {
    width: units.gu(100)
    height: units.gu(75)

    Page {
        title: i18n.tr("Simple Player")

        MediaPlayer {
            id: player
            source: "foo.mp3"
            onStatusChanged: {
                if (status == MediaPlayer.EndOfMedia) {
                    button.pressed = false
                    button.text = i18n.tr("Play")
                }
            }
        }

        Button {
            anchors.centerIn: parent
            id: button
            text: i18n.tr("Play")
            pressed: false
            onClicked: {
                if (player.playbackState == 1){
                    player.stop()
                    pressed = false
                    text = i18n.tr("Play")
                }
                else{
                    pressed = true
                    text = i18n.tr("Stop")
                    player.play()
               }
            }
        }
    }
}

It looks like so:

example player app