十 本地音乐
48 本地音乐页面布局
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12
ColumnLayout{
    Rectangle{
        Layout.fillWidth: true
        width: parent.width
        height: 60
        color: "#00000000"
        Text {
            x:10
            verticalAlignment: Text.AlignBottom
            text: qsTr("本地音乐")
            font.family: window.mFONT_FAMILY
            font.pointSize: 25
        }
    }
    RowLayout{
        height: 80
        Item{
            width: 5
        }
        MusicTextButton{
            btnText: "添加本地音乐"
            btnHeight: 50
            btnWidth: 200
            onClicked: {
            }
        }
        MusicTextButton{
            btnText: "刷新记录"
            btnHeight: 50
            btnWidth: 120
            onClicked: {
            }
        }
        MusicTextButton{
            btnText: "清空记录"
            btnHeight: 50
            btnWidth: 120
            onClicked: {
            }
        }
    }
    MusicListView{
        id:localListView
    }
}
qml
import QtQuick 2.12
import QtQuick.Controls 2.5
Button{
    property alias btnText: self.text
    property alias isCheckable:self.checkable
    property alias isChecked:self.checked
    property alias btnWidth: self.width
    property alias btnHeight: self.height
    id:self
    text: "Button"
    font.family: window.mFONT_FAMILY
    font.pointSize: 14
    background: Rectangle{
        implicitHeight: self.height
        implicitWidth: self.width
        color: self.down||(self.checkable&&self.checked)?"#e2f0f8":"#66e9f4ff"
        radius: 3
    }
    width: 50
    height: 50
    checkable: false
    checked: false
}
qml
49 添加本地音乐
...
import Qt.labs.platform 1.0
ColumnLayout{
    ...
    RowLayout{
        ...
        MusicTextButton{
            ...
            onClicked:fileDialog.open()
        }
        ...
    }
    ...
    FileDialog{
        id:fileDialog
        fileMode: FileDialog.OpenFiles
        nameFilters: ["MP3 Music Files(*.mp3)","FLAC MUsic Files(*.flac)"]
        folder: StandardPaths.standardLocations(StandardPaths.MusicLocation)[0]
        acceptLabel: "确定"
        rejectLabel: "取消"
        onAccepted: {
            var list = []
            for(var index in files){
                var path = files[index]
                var arr = path.split("/")
                var fileNameArr = arr[arr.length-1].split(".")
                
                fileNameArr.pop()
                var fileName = fileNameArr.join(".")
                
                var nameArr = fileName.split("-")
                var name = "续加仪"
                var artist = "续加仪"
                if(nameArr.length>1){
                    artist = nameArr[0]
                    nameArr.shift()
                }
                name = nameArr.join("-")
                list.push({
                              id:path+"",
                              name,artist,
                              url:path+"",
                              album:"本地音乐",
                              type:"1"
                          })
                localListView.musicList  = list
            }
        }
    }
}
qml
50 播放本地音乐
...
Rectangle{
    ...
    function playMusic(){
        if(current<0)return
        if(playList.length<current+1) return
        
        if(playList[current].type==="1"){
            
            playLocalMusic()
        } else {
            
            playWebMusic()
        }
    }
    function playLocalMusic(){
        var currentItem = playList[current]
        mediaPlayer.source =currentItem.url
        mediaPlayer.play()
        musicName = currentItem.name
        musicArtist = currentItem.artist
    }
    function playWebMusic(){
        ...
    }
    ...
}
qml