0

Im trying to create a simple radio app on Ubuntu Touch using the development tool "clickable" yet I cant seem to wrap my head around how to install required QML components.

    MediaPlayer {
        id: player
        source: "https://<some url>.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()
           }
        }
    }


}

The above code results in the following error

..../Main.qml:39 MediaPlayer is not a type

I've tried installing QTmultimedia using apt-get, with no result. How am I suppose to locally add this component to the project? The project seems to have is own version of QML locally

PIRATE FIFI
  • 261
  • 2
  • 10
  • Please provide more info: OS, Qt version, [mcve] etc. Btw, did you try to open one of Qt examples with MediaPlayer? – folibis Mar 28 '23 at 15:13

1 Answers1

0

Depending on your Qt version and your build system (CMake or qmake) you need to link against the corresponding C++ libraries

qmake

QT += multimedia

CMake

find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(my_project PRIVATE Qt6::Multimedia)
iam_peter
  • 3,205
  • 1
  • 19
  • 31