diff options
author | 2024-09-28 03:41:20 +0900 | |
---|---|---|
committer | 2024-09-29 13:19:34 +0900 | |
commit | b4202d3d5aca7842314edbf010e2e8605a6a9e24 (patch) | |
tree | 542146f5e7bcc613fd019ead16c57c94ea65f83f /PlaylistInfo.qml | |
parent | 0404436ada9d6bb695ba1da5b5a2bb68538c2b66 (diff) |
Rework momplay to migrate to Qt6
QtMultimedia has big change from Qt5 to Q6. Existing momiplay
is difficult to migrate to Qt6.
New momiplay is made from Qt Media Player Example. As a result,
it get video player capability.
Bug-AGL: SPEC-5162
Change-Id: Ib754f914fc9d5534721f0d29df689ac11034025a
Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
Diffstat (limited to 'PlaylistInfo.qml')
-rw-r--r-- | PlaylistInfo.qml | 213 |
1 files changed, 213 insertions, 0 deletions
diff --git a/PlaylistInfo.qml b/PlaylistInfo.qml new file mode 100644 index 0000000..4b206f3 --- /dev/null +++ b/PlaylistInfo.qml @@ -0,0 +1,213 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// Copyright (C) 2024 Automotive Grade Linux +// SPDX-License-Identifier: GPL-3.0+ + +pragma ComponentBehavior: Bound + +import QtQuick +import QtQuick.Controls.Fusion +import QtQuick.Dialogs +import QtQuick.Layouts +import QtCore +import MediaControls +import Config + +Rectangle { + id: root + + implicitWidth: 380 + color: Config.mainColor + border.color: "lightgrey" + radius: 10 + + property int currentIndex: -1 + property bool isShuffled: false + property alias mediaCount: files.count + signal playlistUpdated() + signal currentFileRemoved() + + function getSource() { + if (isShuffled) { + let randomIndex = Math.floor(Math.random() * mediaCount) + while (randomIndex == currentIndex) { + randomIndex = Math.floor(Math.random() * mediaCount) + } + currentIndex = randomIndex + } + return files.get(currentIndex).path + } + + function addFiles(index, selectedFiles) { + selectedFiles.forEach(function (file){ + const url = new URL(file) + files.insert(index, + { + path: url, + isMovie: isMovie(url.toString()) + }) + }) + playlistUpdated() + } + + function addFile(index, selectedFile) { + if (index > mediaCount || index < 0) { + index = 0 + currentIndex = 0 + } + files.insert(index, + { + path: selectedFile, + isMovie: isMovie(selectedFile.toString()) + }) + + } + + function isMovie(path) { + const paths = path.split('.') + const extension = paths[paths.length - 1] + const musicFormats = ["mp3", "wav", "aac"] + for (const format of musicFormats) { + if (format === extension) { + return false + } + } + return true + } + + MouseArea { + anchors.fill: root + preventStealing: true + } + +// FileDialog { +// id: folderView +// title: qsTr("Add files to playlist") +// currentFolder: StandardPaths.standardLocations(StandardPaths.MoviesLocation)[0] +// fileMode: FileDialog.OpenFiles +// onAccepted: { +// root.addFiles(files.count, folderView.selectedFiles) +// close() +// } +// } + + ListModel { + id: files + } + + Item { + id: playlist + anchors.fill: root + anchors.margins: 30 + + RowLayout { + id: header + width: playlist.width + + Label { + font.bold: true + font.pixelSize: 20 + text: qsTr("Playlist") + color: Config.secondaryColor + + Layout.fillWidth: true + } + } + + ListView { + id: listView + model: files + anchors.fill: playlist + anchors.topMargin: header.height + 30 + spacing: 20 + + delegate: RowLayout { + id: row + width: listView.width + spacing: 15 + + required property string path + required property int index + required property bool isMovie + + Image { + id: mediaIcon + + states: [ + State { + name: "activeMovie" + when: root.currentIndex === row.index && row.isMovie + PropertyChanges { + mediaIcon.source: Config.iconSource("Movie_Active", false) + } + }, + State { + name: "inactiveMovie" + when: root.currentIndex !== row.index && row.isMovie + PropertyChanges { + mediaIcon.source: Config.iconSource("Movie_Icon") + } + }, + State { + name: "activeMusic" + when: root.currentIndex === row.index && !row.isMovie + PropertyChanges { + mediaIcon.source: Config.iconSource("Music_Active", false) + } + }, + State { + name: "inactiveMusic" + when: root.currentIndex !== row.index && !row.isMovie + PropertyChanges { + mediaIcon.source: Config.iconSource("Music_Icon") + } + } + ] + } + + Label { + Layout.fillWidth: true + elide: Text.ElideRight + font.bold: root.currentIndex === row.index + color: root.currentIndex === row.index ? "#41CD52" : Config.secondaryColor + font.pixelSize: 18 + text: { + const paths = row.path.split('/') + return paths[paths.length - 1] + } + } + } + + remove: Transition { + NumberAnimation { + property: "opacity" + from: 1.0 + to: 0.0 + duration: 400 + } + } + + add: Transition { + NumberAnimation { + property: "opacity" + from: 0.0 + to: 1.0 + duration: 400 + } + NumberAnimation { + property: "scale" + from: 0.5 + to: 1.0 + duration: 400 + } + } + + displaced: Transition { + NumberAnimation { + properties: "y" + duration: 600 + easing.type: Easing.OutBounce + } + } + } + } +} |