9

I've installed the Ubuntu QML Toolkit Preview as per the instructions on http://developer.ubuntu.com/get-started/gomobile/ (with a minor fiddle to get it working on 12.04). I'm trying to write an app that plays a sound file. Aparrently you can do this using QtMultiMediakit in QtQuick 1, but not in QtQuick 2 as used by the toolkit.

Is it possible to write an app using the toolkit that plays sound?

David Planella
  • 15,420
  • 11
  • 77
  • 141
marxjohnson
  • 701
  • 1
  • 6
  • 21
  • Just of interest, which instructions did you follow to install Ubuntu on Nexus 7? – mlvljr Jan 07 '13 at 11:50
  • 1
    I'm not sure which part of my post suggests I'm running Ubuntu on a Nexus 7, but I'm not. – marxjohnson Jan 08 '13 at 14:11
  • okay, I am looking up to doing that myself, and obviously was too anxious :) But isn't Ubuntu QML toolkit targeted at phones/tablets? – mlvljr Jan 08 '13 at 21:16

2 Answers2

8

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

marxjohnson
  • 701
  • 1
  • 6
  • 21
3

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

andrewsomething
  • 37,262
  • 13
  • 93
  • 140