Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
Just of interest, which instructions did you follow to install Ubuntu on Nexus 7? –  mlvljr Jan 7 '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 8 '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 8 '13 at 21:16
add comment

2 Answers

up vote 7 down vote accepted

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

share|improve this answer
    
In my case, I seemed to need libqt5multimedia5-plugins installed and the SDK didn't pull this in by default. –  andrewsomething Jul 30 '13 at 19:45
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.