Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Error: Cannot assign [undefined] to QUrl
QtWS25 Last Chance

Error: Cannot assign [undefined] to QUrl

Scheduled Pinned Locked Moved Solved QML and Qt Quick
17 Posts 2 Posters 7.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Naveen_DN Offline
    Naveen_DN Offline
    Naveen_D
    wrote on last edited by Naveen_D
    #1

    Hi all ,
    i am developing a music player module for car HMI in QML, for that i am importing QtMultiMedia 5.0 for the functionality of music. i am using folderListModel to get the songs which are there in my project songs folder. The problem i am facing is, whenever i try to play the songs using my application i get the following error:

    Error: Cannot assign [undefined] to QUrl
    on this line mediaplayer.source= items.get(index,"filePath")

    can anyone please tell me what is wrong in the code? thanks

    my code:

    import QtQuick 2.5
    import QtQuick.Controls 1.4
    import QtQuick.Layouts 1.1
    import QtGraphicalEffects 1.0
    import QtQuick.Controls.Styles 1.4
    import QtMultimedia 5.0
    import Qt.labs.folderlistmodel 2.1
    
    import "../Common"
    
    Rectangle{
        id: musicMainrectangle
        property int  rowSpacing: 50
        property int  columnSpacing: 50
        implicitHeight: applicationWindow.height-250
        implicitWidth: applicationWindow.width
        anchors.horizontalCenter: applicationWindow.horizontalCenter
        color: "transparent"
    
        // music functionality //
        MediaPlayer{
            id: musicplayer
        }
    
    
        Item {
            id: playLogic
    
            property int index: -1
            property MediaPlayer mediaplayer: musicplayer
            property FolderListModel items: FolderListModel{
                folder: "Songs"
                nameFilters: ["*.mp3"]
            }
    
            function init(){
                if(mediaplayer.playbackState===1){
                        mediaplayer.pause();
                } else if(mediaplayer.playbackState===2){
                    mediaplayer.play();
                }else {
                   setIndex(0)
                }
            }
    
            function setIndex(i) {
                index= i
    
                if(index < 0 || index> items.count){
                    index= -1
                    mediaplayer.source="";
                }else {
                    mediaplayer.source= items.get(index,"filePath")
                    mediaplayer.play();
                }
            }
    
            function next(){
                setIndex(index+1)
            }
    
            function previous() {
                setIndex(index-1)
            }
    
            function msToTime(duration) {
                var seconds= parseInt((duration/1000)%60)
                var minutes= parseInt((duration/(1000*60))%60)
    
                minutes =(minutes < 10) ? "0" + minutes : minutes
                seconds =(seconds < 10) ? "0" + seconds : seconds
    
                return (minutes+":"+seconds);
            }
    
            Connections {
                target: playLogic.mediaplayer
    
                onPaused : {
                    playPauseimage.source= "qrc:/images/002-play-button-2.png"
                }
    
                onPlaying : {
                   playPauseimage.source= "qrc:/images/019-pause-button.png"
                }
    
                onStopped : {
                    playPauseimage.source= "qrc:/images/002-play-button-2.png"
                    if(playLogic.mediaplayer.status=== MediaPlayer.EndOfMedia) {
                        playLogic.next()
                    }
                }
    
                onMediaObjectChanged: {
                    if(playLogic.mediaplayer.mediaObject) {
                        playLogic.mediaplayer.mediaObject.notifyInterval = 50
                    }
                }
            }
        }
    
        // back, options, settings //
        RowLayout {
            id: topContentRow
            spacing: rowSpacing*6
            anchors.horizontalCenter: parent.horizontalCenter
            Commonrectangle{
                id:backimgrect
                rectWidth: musicMainrectangle.width/18
                rectHeight: musicMainrectangle.height/16
                rectColor: "transparent"
                imageSource: "qrc:/images/back_grey.png"
                MouseArea {
                    id: backmousearea
                    anchors.fill: parent
                    onClicked: {
                        initialContentLoader.active= true
                        initialContentLoader.visible= true
                        shortcuticonbarLoader.visible= false
                        shortcuticonbarLoader.active= false
                        musicContentLoader.active= false
                        musicContentLoader.visible= false
                    }
                }
            }
            RowLayout{
                Commonrectangle {
                    id: browserect
                    rectColor: "#ffffff"
                    rectWidth: musicMainrectangle.width/6
                    rectHeight: musicMainrectangle.height/18
                    opacity: 0.5
                    LabelTitle {
                        id: browseLabel
                        text: "Browse"
                        anchors.centerIn: parent
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#ffffff"
                        font.capitalization: Font.AllUppercase
                        font.pixelSize: fontSizeSubheading
                        font.bold: true
                    }
                    RectangularGlow {
                        id: browserectglow
                        anchors.fill: browserect
                        glowRadius: 10
                        spread: 0.2
                        color: "white"
                        visible: false
                        cornerRadius: browserect.radius + glowRadius
                    }
                    MouseArea {
                        id: browseMousearea
                        anchors.fill: parent
                        onPressed:{
                            browseContentrect.visible= true
                            animation.start()
                            if(nowplayingrectglow.visible === true)
                            {
                                nowplayingrectglow.visible= false
                                browserectglow.visible= true
                            } else {
                                nowplayingrectglow.visible= true
                                browserectglow.visible= false
                                browseContentrect.visible= false
                            }
                        }
                        NumberAnimation
                        {
                            id: animation
                            target: browseContentrect
                            property: "y"
                            from: 0
                            to: 500
                            duration: 1000
                        }
                    }
                }
                Commonrectangle {
                    id: nowplayingrect
                    rectColor: "#ffffff"
                    rectWidth: musicMainrectangle.width/6
                    rectHeight: musicMainrectangle.height/18
                    opacity: 0.5
                    LabelTitle {
                        id: nowplayingLabel
                        text: "Now Playing"
                        anchors.centerIn: parent
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#ffffff"
                        font.capitalization: Font.AllUppercase
                        font.pixelSize: fontSizeSubheading
                        font.bold: true
                    }
                    RectangularGlow {
                        id: nowplayingrectglow
                        anchors.fill: nowplayingrect
                        glowRadius: 10
                        spread: 0.2
                        color: "white"
                        visible: true
                        cornerRadius: nowplayingrect.radius + glowRadius
                    }
                }
            }
            Commonrectangle{
                id:settingsimgrect
                rectWidth: musicMainrectangle.width/18
                rectHeight: musicMainrectangle.height/17
                rectColor: "transparent"
                imageSource: "qrc:/images/settings_mdpi.png"
                MouseArea {
                    id: settingsMousearea
                    anchors.fill: parent
                    onClicked: {
                        settingsMenu.__popup(Qt.rect(settingsimgrect.x, settingsimgrect.height,0,30),0,0)
                    }
                }
                Menu{
                    id: settingsMenu
    
                    MenuItem {
                        text: qsTr("Equilizer")
                        onTriggered: {
                            equilizerContentrect.visible= true
                        }
                    }
                    MenuSeparator{}
                    MenuItem {
                        text: qsTr("Front & Rear speakers")
                        //                    onTriggered: {
                        //                        popup.selectAccentColor = false
                        //                        popup.open()
                        //                    }
                    }
                    MenuSeparator{}
                    MenuItem {
                        text: qsTr("Source Vol Change")
                        //      /          states: State {
                        //              name: "moved"; when: mouseArea.pressed
                        //              PropertyChanges { target: rect; x: 50; y: 50 }
                        //          }
    
                        //          transitions: Transition {
                        //              NumberAnimation {
                        //                  properties: "x,y"
                        //                  to : 50
                        //                  duration: 600
                        //                  easing.type: Easing.InOutQuad
                        //              }
                        //          }              onTriggered: {
                        //                        popup.selectAccentColor = true
                        //                        popup.open()
                        //                    }
                    }
                    style: MenuStyle {               // the menus items
                        id: goreStyle
    
                        frame: Rectangle {
    
                            color: "#616161"
                            height: 200
                        }
    
                        itemDelegate {
                            background: Rectangle {
                                color:  styleData.selected || styleData.open ? "#eceff1" : "#616161"
                                radius: styleData.selected ? 3 : 0
    
                            }
    
                            label: Label {
                                color: styleData.selected ? "#616161" : "#eceff1"
                                text: styleData.text
                            }
                        }
                    }
                }
            }
        }
    
        // albumart, volume control //
        RowLayout {
            id: musicplayerrow
            spacing:rowSpacing
            anchors.top: topContentRow.bottom
            anchors.topMargin: 50
            anchors.horizontalCenter: parent.horizontalCenter
            ColumnLayout{
                id: musicartandvolume
                spacing: columnSpacing
                Commonrectangle {
                    id: musicartrect
                    rectWidth: (musicMainrectangle.width/3)
                    rectHeight: musicMainrectangle.height/2
                    rectColor: "transparent"
                    Image {
                        id: musicnoteimage
                        anchors.centerIn: parent
                        source: "qrc:/images/music_icon.png"
                        width: parent.width
                        height: parent.height-100
                    }
                }
                RowLayout{
                    id: volumerow
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors{
                        bottom: musicartandvolume.bottom
                        bottomMargin: -50
                    }
                    Commonrectangle{
                        id: volimageRect
                        rectWidth: musicMainrectangle.width/21
                        rectHeight: musicMainrectangle.height/19
                        rectColor: "transparent"
                        imageSource: "qrc:/images/volume_up_avg.png"
                    }
                    VerticleDivider{dividerColor: "#ffffff"}
    
                    CommonSlider{
                        id: volumeSlider
                        minimumValue: 0
                        maximumValue: 100
                        sliderWidth: musicMainrectangle.width/6
                        value: 50
                        stepSize: 1.0
                        updateValueWhileDragging: true
    
                        style: SliderStyle {
                            groove:  Rectangle {
                                id: grooveMainrect
                                height: 8
                                antialiasing: true
                                radius: 5
                                color: "#847878"
                                Rectangle {
                                    id: groovechildrect
                                    width: (parent.width * volumeSlider.value)/volumeSlider.maximumValue
                                    height: parent.height
                                    color: Qt.lighter("#7ea6d6", 1.2)
                                    radius: parent.radius
                                }
                            }
                            handle: Rectangle {
                                id:handlemainrect
                                height: 40
                                width: 40
                                radius: (width+height)/2
                                anchors.verticalCenter: parent.verticalCenter
                                color: Qt.lighter("#7ea6d6", 1.2)
                                LabelTitle {
                                    id: volumedataLabel
                                    text: volumeSlider.value
                                    anchors.centerIn: parent
                                    elide: Label.ElideRight
                                    color: "#000000"
                                    font.pixelSize: fontSizeBodyAndButton
                                    font.family:"Myriad Pro"
                                }
    
                            }
                        }
                        onValueChanged: {
                            if(pressed)
                            {
                                console.log("pressed")
                                if(volumeSlider.value>= 65)
                                {
                                    volimageRect.imageSource="qrc:/images/volume_high.png"
                                }
                                else if(volumeSlider.value>30 && volumeSlider.value<65)
                                {
                                    volimageRect.imageSource ="qrc:/images/volume_up_avg.png"
                                }
                                else if(volumeSlider.value<30 && volumeSlider.value !=0)
                                {
                                    volimageRect.imageSource = "qrc:/images/volume_low.png"
                                }
                                else if(volumeSlider.value == 0)
                                {
                                    volimageRect.imageSource= "qrc:/images/volume_mute.png"
                                }
                            }
                        }
                    }
                }
            }
    
            // music options play, pause, next, previous //
            Commonrectangle {
                id: musicoptionsrect
                rectWidth: (musicMainrectangle.width/3)+100
                rectHeight: musicMainrectangle.height-100
                rectColor: "transparent"
                ColumnLayout {
                    id: musiccontentcolumn
                    spacing: columnSpacing*2
                    anchors.centerIn: parent
                    RowLayout{
                        LabelTitle {
                            id: timeLabel
                            text: "Song Label"
                            elide: Label.ElideRight
                            horizontalAlignment: Qt.AlignHCenter
                            verticalAlignment: Qt.AlignVCenter
                            color: "#ffffff"
                            font.pixelSize: fontSizeDisplay3
                            font.family:"Myriad Pro"
                        }
                    }
                    RowLayout {
                        id: playpauserow
                        spacing: rowSpacing
                        anchors.horizontalCenter: parent.horizontalCenter
                        Commonrectangle{
                            rectColor: "transparent"
                            rectWidth: musicMainrectangle.width/15
                            rectHeight: musicMainrectangle.height/13
                            imageSource: "qrc:/images/ic_skip_previous_white_48dp.png"
                        }
                        Commonrectangle{
                            rectColor: "transparent"
                            rectWidth: musicMainrectangle.width/10
                            rectHeight: musicMainrectangle.height/7
                            Image {
                                id: playPauseimage
                                source: "qrc:/images/002-play-button-2.png"
                                width: parent.width
                                height: parent.height
                                state: "none"
                                MouseArea {
                                    anchors.fill: parent
                                    onClicked: playLogic.init()
                                    onPressed: playPauseimage.state = "pressed"
                                    onReleased: playPauseimage.state = "none"
                                }
                                states: State {
                                    name: "pressed"
                                    when: mouseArea.pressed
                                    PropertyChanges {target: playPauseimage; scale: 0.8}
                                }
                                transitions: Transition {
                                    NumberAnimation {properties: scale; duration: 100;easing.type: Easing.InOutQuad}
                                }
                            }
                        }
                        Commonrectangle{
                            rectColor: "transparent"
                            rectWidth: musicMainrectangle.width/15
                            rectHeight: musicMainrectangle.height/13
                            imageSource: "qrc:/images/ic_skip_next_white_48dp.png"
                        }
                    }
                    RowLayout{
                        id: musicplaysliderrow
                        anchors.top: playpauserow.bottom
                        anchors.topMargin: columnSpacing*2
                        anchors.horizontalCenter: parent.horizontalCenter
                        CommonSlider {}
                    }
                    RowLayout{
                        id: suffleandrepeatRow
                        spacing: rowSpacing*2
                        anchors {
                            bottom: parent.bottom
                            horizontalCenter: parent.horizontalCenter
                        }
                        Commonrectangle{
                            rectColor: "transparent"
                            rectWidth: musicMainrectangle.width/17
                            rectHeight: musicMainrectangle.height/14
                            imageSource: "qrc:/images/ic_repeat_white_48dp.png"
                            MouseArea{
                                id: repeatmousearea
                                anchors.fill: parent
                                onClicked: {
                                    if(repeatRect.visible== false)
                                    {repeatRect.visible= true} else {repeatRect.visible= false}
                                }
                            }
    
                            Commonrectangle{
                                id:repeatRect
                                width: parent.width
                                height: parent.height
                                rectColor: "transparent"
                                visible: false
                                Image {
                                    id: repeatImage
                                    source: "qrc:/images/ic_repeat_white_48dp.png"
                                    width: parent.width
                                    height: parent.height
                                }
                                Glow {
                                    anchors.fill: repeatImage
                                    radius: 4
                                    samples: 10
                                    color: "white"
                                    source: repeatImage
                                }
                            }
                        }
                        Commonrectangle{
                            rectColor: "transparent"
                            rectWidth: musicMainrectangle.width/17
                            rectHeight: musicMainrectangle.height/14
                            imageSource: "qrc:/images/ic_shuffle_white_48dp.png"
                            MouseArea{
                                id: shufflemousearea
                                anchors.fill: parent
                                onClicked: {
                                    if(shuffleRect.visible== false)
                                    { shuffleRect.visible = true} else {shuffleRect.visible= false}
                                }
                            }
    
                            Commonrectangle{
                                id:shuffleRect
                                width: parent.width
                                height: parent.height
                                rectColor: "transparent"
                                visible: false
                                Image {
                                    id: shuffleImage
                                    source: "qrc:/images/ic_shuffle_white_48dp.png"
                                    width: parent.width
                                    height: parent.height
                                }
                                Glow {
                                    anchors.fill: shuffleImage
                                    radius: 4
                                    samples: 10
                                    color: "white"
                                    source: shuffleImage
                                }
                            }
                        }
                    }
                }
            }
        }
        Commonrectangle{
            id: browseContentrect
            rectHeight: parent.height-25
            rectWidth: (parent.width/2)-50
            visible: false
            anchors{
                left: parent.left
                leftMargin: 40
                top: topContentRow.bottom
                topMargin: 10
            }
            rectColor: "#616161"
        }
        Commonrectangle{
            id: equilizerContentrect
            rectHeight: (parent.height/2)+250
            rectWidth: (parent.width-150)
            visible: false
            anchors{
                top: topContentRow.bottom
                topMargin: 50
                horizontalCenter: parent.horizontalCenter
            }
            rectColor: "#616161"
            ColumnLayout{
                id: equilizerColumnlayout
                width: parent.width
                height: parent.height
                anchors{
                    horizontalCenter: parent.horizontalCenter
                }
                RowLayout{
                    id: equalizerlabelRow
                    anchors{
                        horizontalCenter: parent.horizontalCenter
                    }
                    LabelTitle {
                        id: equalizerLabel
                        text: "Equalizer"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeHeadline
                        font.capitalization: Font.AllUppercase
                        font.family:"Myriad Pro"
                    }
                }
                RowLayout{
                    id: equilizerRowlayout
                    spacing: rowSpacing
                    anchors{
                        horizontalCenter: parent.horizontalCenter
                    }
                    ColumnLayout{
                    VerticleSlider{anchors.horizontalCenter: parent.horizontalCenter;sliderValue: 20}
                    LabelTitle {
                        id: preampLabel
                        text: "Preamp"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeBodyAndButton
                        font.family:"Myriad Pro"
                    }
                    }
                    ColumnLayout{
                    VerticleSlider{anchors.horizontalCenter: parent.horizontalCenter;sliderValue: 65}
                    LabelTitle {
                        id: bassLabel
                        text: "Bass"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeBodyAndButton
                        font.family:"Myriad Pro"
                    }
                    }
                    ColumnLayout{
                    VerticleSlider{anchors.horizontalCenter: parent.horizontalCenter;sliderValue: 40}
                    LabelTitle {
                        id: hz31Label
                        text: "31"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeBodyAndButton
                        font.family:"Myriad Pro"
                    }
                    }
                    ColumnLayout{
                    VerticleSlider{anchors.horizontalCenter: parent.horizontalCenter;sliderValue: 35}
                    LabelTitle {
                        id: hz62Label
                        text: "62"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeBodyAndButton
                        font.family:"Myriad Pro"
                    }
                    }
                    ColumnLayout{
                    VerticleSlider{anchors.horizontalCenter: parent.horizontalCenter;sliderValue: 28}
                    LabelTitle {
                        id: hz125Label
                        text: "125"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeBodyAndButton
                        font.family:"Myriad Pro"
                    }
                    }
                    ColumnLayout{
                    VerticleSlider{anchors.horizontalCenter: parent.horizontalCenter;sliderValue: 55}
                    LabelTitle {
                        id: hz250Label
                        text: "250"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeBodyAndButton
                        font.family:"Myriad Pro"
                    }
                    }
                    ColumnLayout{
                    VerticleSlider{anchors.horizontalCenter: parent.horizontalCenter;sliderValue: 50}
                    LabelTitle {
                        id: hz500Label
                        text: "500"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeBodyAndButton
                        font.family:"Myriad Pro"
                    }
                    }
                    ColumnLayout{
                    VerticleSlider{anchors.horizontalCenter: parent.horizontalCenter;sliderValue: 45}
                    LabelTitle {
                        id: hz1kLabel
                        text: "1k"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeBodyAndButton
                        font.family:"Myriad Pro"
                    }
                    }
                    ColumnLayout{
                    VerticleSlider{anchors.horizontalCenter: parent.horizontalCenter;sliderValue: 25}
                    LabelTitle {
                        id: hz2kLabel
                        text: "2k"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeBodyAndButton
                        font.family:"Myriad Pro"
                    }
                    }
                    ColumnLayout{
                    VerticleSlider{anchors.horizontalCenter: parent.horizontalCenter;sliderValue: 20}
                    LabelTitle {
                        id: hz4kLabel
                        text: "4k"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeBodyAndButton
                        font.family:"Myriad Pro"
                    }
                    }
                    ColumnLayout{
                    VerticleSlider{anchors.horizontalCenter: parent.horizontalCenter;sliderValue: 70}
                    LabelTitle {
                        id: hz8kLabel
                        text: "8k"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeBodyAndButton
                        font.family:"Myriad Pro"
                    }
                    }
                    ColumnLayout{
                    VerticleSlider{anchors.horizontalCenter: parent.horizontalCenter;sliderValue: 55}
                    LabelTitle {
                        id: hz10kLabel
                        text: "10k"
                        elide: Label.ElideRight
                        horizontalAlignment: Qt.AlignHCenter
                        verticalAlignment: Qt.AlignVCenter
                        color: "#00bcd4"
                        font.pixelSize: fontSizeBodyAndButton
                        font.family:"Myriad Pro"
                    }
                    }
                }
                RowLayout{
                    id: okCancelRowlayout
                    spacing: rowSpacing
                    anchors{
                        horizontalCenter: parent.horizontalCenter
                    }
                    CommonButton{
                        id: okbutton
                        width: equilizerColumnlayout.width/8
                        height: equilizerColumnlayout.height/14
                        butttonText: "OK"
                        style: ButtonStyle{
                            background: Rectangle{
                                id: okbuttonbackground
                                implicitHeight: parent.height
                                implicitWidth: parent.width
                                color: "#00bcd4"
                                opacity: okbutton.pressed ? 0.5: 1.0
                                radius: 5
                            }
                        }
                        MouseArea{
                            id: okbuttonmousearea
                            anchors.fill: parent
                            onClicked: {
                               equilizerContentrect.visible= false
                            }
                        }
                    }
                    CommonButton{
                        id: cancelbutton
                        width: equilizerColumnlayout.width/8
                        height: equilizerColumnlayout.height/14
                        butttonText: "Cancel"
                        style: ButtonStyle{
                            background: Rectangle{
                                id: cancelbuttonbackground
                                implicitHeight: parent.height
                                implicitWidth: parent.width
                                color: "#00bcd4"
                                opacity: cancelbutton.pressed ? 0.5: 1.0
                                radius: 5
                            }
                        }
                        MouseArea{
                            id: canbuttonmousearea
                            anchors.fill: parent
                            onClicked: {
                               equilizerContentrect.visible= false
                            }
                        }
                    }
                }
            }
        }
    }
    
    

    Naveen_D

    1 Reply Last reply
    1
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Perhaps items really is empty or undefined? Try printing it with console.log().

      (Z(:^

      Naveen_DN 1 Reply Last reply
      1
      • sierdzioS sierdzio

        Perhaps items really is empty or undefined? Try printing it with console.log().

        Naveen_DN Offline
        Naveen_DN Offline
        Naveen_D
        wrote on last edited by
        #3

        @sierdzio i tried this with a small example, what i am doing is on a click of button i am trying to play the song. here i am not getting any error but i didn't get output also, on click of button nothing happens.. i tried printing using console, here is the minimal code which i am trying...

        import QtQuick 2.6
        import QtQuick.Controls 1.5
        import QtQuick.Controls.Styles 1.4
        import QtQuick.Layouts 1.1
        import QtMultimedia 5.0
        import Qt.labs.folderlistmodel 1.0
        
        ApplicationWindow {
            visible: true
            width: 640
            height: 480
        
            MediaPlayer {
                id: player
            }
        
            Item {
                id: playerLogic
        
                property int index: -1
                property MediaPlayer mediaplayer: player
                property FolderListModel items: FolderListModel{
                    folder: "Songs"
                    nameFilters: ["*.mp3"]
                }
        
                function init(){
                    console.log("Entered init function")
                    if(mediaplayer.PlayingState===1)
                    {
                        console.log("playing state is 1")
                        mediaplayer.pause();
                    }else if(mediaplayer.PlayingState===2){
                        console.log("playing state is 2")
                        mediaplayer.play();
                    } else {
                        console.log("calling index function")
                        setIndex(0);
                    }
                }
        
                function setIndex(i){
                    console.log("entered setindex function")
                    index= i
                    if(index<0 || index> items.count){
                        console.log("checking if condition")
                        index=-1;
                        mediaplayer.source="";
                    }else {
                        console.log("else part")
                        mediaplayer.source=items.get(index,"filePath");
                        console.log("before playing the song")
                        mediaplayer.play();
                    }
                }
            }
        
            Button{
                id: playpausebutton
                anchors.centerIn: parent
                width: 100
                height: 80
                text: "PlayMusic"
                state: "none"
                style: ButtonStyle{
                    background: Rectangle{
                        id: buttonbackground
                        implicitHeight: parent.height
                        implicitWidth: parent.width
                        color: "#00bcd4"
                        opacity: playpausebutton.pressed ? 0.5: 1.0
                        radius: 5
                    }
                }
                MouseArea {
                    id: buttonmousearea
                    anchors.fill: parent
                    onClicked: playerLogic.init()
                }
            }
        
        }
        
        

        output :
        QML debugging is enabled. Only use this in a safe environment.
        libva info: VA-API version 0.37.0
        libva info: va_getDriverName() returns 0
        libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/fglrx_drv_video.so
        libva info: va_openDriver() returns -1
        libva info: VA-API version 0.37.0
        libva info: va_getDriverName() returns 0
        libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/fglrx_drv_video.so
        libva info: va_openDriver() returns -1
        libva info: VA-API version 0.37.0
        libva info: va_getDriverName() returns 0
        libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/fglrx_drv_video.so
        libva info: va_openDriver() returns -1
        libva info: VA-API version 0.37.0
        libva info: va_getDriverName() returns 0
        libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/fglrx_drv_video.so
        libva info: va_openDriver() returns -1
        qml: Entered init function
        qml: calling index function
        qml: entered setindex function
        qml: else part
        qml: before playing the song
        qml: Entered init function
        qml: calling index function
        qml: entered setindex function
        qml: else part
        qml: before playing the song

        Naveen_D

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          No, I mean print the items.

                         console.log("Items:" + items)
                          mediaplayer.source=items.get(index,"filePath");
                          console.log("before playing the song")
                          mediaplayer.play();
          

          Looks like something is bad in your env, too, see these lines: libva info: va_openDriver() returns -1 seems like the audio driver is not working?

          (Z(:^

          Naveen_DN 1 Reply Last reply
          0
          • sierdzioS sierdzio

            No, I mean print the items.

                           console.log("Items:" + items)
                            mediaplayer.source=items.get(index,"filePath");
                            console.log("before playing the song")
                            mediaplayer.play();
            

            Looks like something is bad in your env, too, see these lines: libva info: va_openDriver() returns -1 seems like the audio driver is not working?

            Naveen_DN Offline
            Naveen_DN Offline
            Naveen_D
            wrote on last edited by
            #5

            @sierdzio When i print the items, i get the following output:
            qml: items are: QQuickFolderListModel(0xf12ac0)

            Naveen_D

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Ah, not very helpful. Try printing out all items in a loop, then.

              (Z(:^

              Naveen_DN 1 Reply Last reply
              0
              • sierdzioS sierdzio

                Ah, not very helpful. Try printing out all items in a loop, then.

                Naveen_DN Offline
                Naveen_DN Offline
                Naveen_D
                wrote on last edited by
                #7

                @sierdzio i am not getting how to print the items in foldermodellist i tried with the following code but didn't get output:

                for (var j=0; j<items.count;j++){
                                    console.log("items"+ items(j))
                                }
                

                is this the correct way ?

                Naveen_D

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  Almost :-)

                  for (var j=0; j<items.count;j++){
                      console.log("item:"+ items.get(index,"filePath"))
                  }
                  

                  Maybe that will help us pinpoint the issue.

                  (Z(:^

                  Naveen_DN 1 Reply Last reply
                  0
                  • sierdzioS sierdzio

                    Almost :-)

                    for (var j=0; j<items.count;j++){
                        console.log("item:"+ items.get(index,"filePath"))
                    }
                    

                    Maybe that will help us pinpoint the issue.

                    Naveen_DN Offline
                    Naveen_DN Offline
                    Naveen_D
                    wrote on last edited by Naveen_D
                    #9

                    @sierdzio Hi, i tried printing those items, but i am getting the same error again (Error: Cannot assign [undefined] to QUrl), also when i try to print those items, i am not able to find the auto get method for items(i.e items.get() method) and it is not entering the for loop.
                    what can be the possible solution? thanks

                    Naveen_D

                    1 Reply Last reply
                    0
                    • sierdzioS Offline
                      sierdzioS Offline
                      sierdzio
                      Moderators
                      wrote on last edited by
                      #10

                      Please try:

                      • print items.count and items.get(0, "filePath")
                      • rewrite items to be a normal QML component and not a property (see example code in the docs) and see if it works
                      • make sure the path is OK :-)

                      (Z(:^

                      Naveen_DN 1 Reply Last reply
                      0
                      • sierdzioS sierdzio

                        Please try:

                        • print items.count and items.get(0, "filePath")
                        • rewrite items to be a normal QML component and not a property (see example code in the docs) and see if it works
                        • make sure the path is OK :-)
                        Naveen_DN Offline
                        Naveen_DN Offline
                        Naveen_D
                        wrote on last edited by
                        #11

                        @sierdzio

                        print items.count and items.get(0, "filePath")

                        output:
                        qml: items count >> 0
                        qml: items at 0 position >> undefined

                        rewrite items to be a normal QML component and not a property (see example code in the docs) and see if it works

                        i made the following changes, pls rectify if there is any mistake

                        FolderListModel{
                                    id: items
                                    folder: "/home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs"
                                    nameFilters: ["*.mp3"]
                                }
                        

                        after making changes i am getting the following output:

                        qml: Entered init function
                        qml: calling index function
                        qml: entered setindex function
                        qml: else part
                        qml: items count >> 0
                        qml: items at 0 position >> undefined
                        qrc:/main.qml:58: Error: Cannot assign [undefined] to QUrl

                        Naveen_D

                        1 Reply Last reply
                        0
                        • sierdzioS Offline
                          sierdzioS Offline
                          sierdzio
                          Moderators
                          wrote on last edited by
                          #12

                          OK, so now at least we know this:

                          • issue is not related to QtMultimedia
                          • issue is with FolderListModel
                          • "Cannot assign [undefined]" is there, because items is empty (no .mp3 files are detected in Songs folder)

                          Try using URL instead of path:

                          folder: "file:///home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs"
                          

                          Relative and absolute paths should work, but apparently something fails here. Also, of course, please make sure there are some MP3s in that dir.

                          (Z(:^

                          Naveen_DN 1 Reply Last reply
                          0
                          • sierdzioS sierdzio

                            OK, so now at least we know this:

                            • issue is not related to QtMultimedia
                            • issue is with FolderListModel
                            • "Cannot assign [undefined]" is there, because items is empty (no .mp3 files are detected in Songs folder)

                            Try using URL instead of path:

                            folder: "file:///home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs"
                            

                            Relative and absolute paths should work, but apparently something fails here. Also, of course, please make sure there are some MP3s in that dir.

                            Naveen_DN Offline
                            Naveen_DN Offline
                            Naveen_D
                            wrote on last edited by
                            #13

                            @sierdzio yup, now its detecting the mp3 files, i am getting the following output,

                            qml: Entered init function
                            qml: calling index function
                            qml: entered setindex function
                            qml: else part
                            qml: items count >> 5
                            qml: items at 0>> /home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs/Cinema_Choopista-StarMusiQ.Com.mp3
                            qml: before playing the song

                            But i am not sure the song is playing or not, because i am not getting sound. Does it require anything else for this?

                            Naveen_D

                            sierdzioS 1 Reply Last reply
                            0
                            • Naveen_DN Naveen_D

                              @sierdzio yup, now its detecting the mp3 files, i am getting the following output,

                              qml: Entered init function
                              qml: calling index function
                              qml: entered setindex function
                              qml: else part
                              qml: items count >> 5
                              qml: items at 0>> /home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs/Cinema_Choopista-StarMusiQ.Com.mp3
                              qml: before playing the song

                              But i am not sure the song is playing or not, because i am not getting sound. Does it require anything else for this?

                              sierdzioS Offline
                              sierdzioS Offline
                              sierdzio
                              Moderators
                              wrote on last edited by
                              #14

                              Nice, I'm glad to hear that problem is solved.

                              @Naveen_D said in Error: Cannot assign [undefined] to QUrl:

                              But i am not sure the song is playing or not, because i am not getting sound. Does it require anything else for this?

                              I'm not familiar with QtMultimedia, I can't help here unfortunately. My first guesses are:

                              • check if you have gstreamer 0.1 installed
                              • check if you have mp3 codecs installed (mp3lame or something)
                              • check some QtMultimedia examples in Qt Creator - does the sound work there?

                              (Z(:^

                              Naveen_DN 1 Reply Last reply
                              1
                              • sierdzioS sierdzio

                                Nice, I'm glad to hear that problem is solved.

                                @Naveen_D said in Error: Cannot assign [undefined] to QUrl:

                                But i am not sure the song is playing or not, because i am not getting sound. Does it require anything else for this?

                                I'm not familiar with QtMultimedia, I can't help here unfortunately. My first guesses are:

                                • check if you have gstreamer 0.1 installed
                                • check if you have mp3 codecs installed (mp3lame or something)
                                • check some QtMultimedia examples in Qt Creator - does the sound work there?
                                Naveen_DN Offline
                                Naveen_DN Offline
                                Naveen_D
                                wrote on last edited by Naveen_D
                                #15

                                Thanks for the information,
                                But previously i had tried to play songs using this and it was working fine, i found out that when i directly give source in the media player and play it is working fine the song is playing, but when i give the folderlistmodel path using the get method it is not working.
                                also i tried to print the path, when i give the direct source path, the path printed is the URL path but when it takes through the folderlistmodel, it is the normal path

                                i.e Direct source path with song if i give, the path set is :
                                "file:///home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs/David Guetta - Love Don't Let Me Go (Memorax Remix) [FREE].mp3"

                                and through folderlistmodel with the index, the path set is :
                                "/home/ubuntu/Documents/Sample_Examples_Qt_Qml/DummyMusicPlayer/Songs/David Guetta - Love Don't Let Me Go (Memorax Remix) [FREE].mp3"

                                Can anyone please suggest the possible solution.
                                Thanks

                                Naveen_D

                                1 Reply Last reply
                                1
                                • Naveen_DN Offline
                                  Naveen_DN Offline
                                  Naveen_D
                                  wrote on last edited by
                                  #16

                                  I have solved the issue,

                                  mediaplayer.source=items.get(index,"filePath");
                                  

                                  I was using filePath, instead of this i used fileURL, the issue got resolved.

                                  @sierdzio thanks alot for your help.

                                  Thanks

                                  Naveen_D

                                  1 Reply Last reply
                                  3
                                  • sierdzioS Offline
                                    sierdzioS Offline
                                    sierdzio
                                    Moderators
                                    wrote on last edited by
                                    #17

                                    Cool, good to hear that :) Please mark the topic as solved, too.

                                    (Z(:^

                                    1 Reply Last reply
                                    1

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved