X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=app%2FMediaPlayer.qml;h=95bc22bc32bab0ec1a12326977e55cc92afacb16;hb=219b527adbc7996f4ae2e73732114d2daa17c9c5;hp=438ff20e8774e5e7a11d9371e2c2f3a3dcc2a639;hpb=74c70d0ac87d4674646e53d2af781d9084a7ea06;p=apps%2Fmediaplayer.git diff --git a/app/MediaPlayer.qml b/app/MediaPlayer.qml index 438ff20..95bc22b 100644 --- a/app/MediaPlayer.qml +++ b/app/MediaPlayer.qml @@ -14,16 +14,19 @@ * limitations under the License. */ -import QtQuick 2.6 -import QtQuick.Layouts 1.1 -import QtQuick.Controls 2.0 -import QtMultimedia 5.6 +import QtQuick 2.11 +import QtQuick.Layouts 1.11 +import QtQuick.Controls 2.4 +import QtQuick.Window 2.13 + import AGL.Demo.Controls 1.0 -import 'api' as API ApplicationWindow { id: root + width: container.width * container.scale + height: container.height * container.scale + Item { id: player @@ -31,77 +34,104 @@ ApplicationWindow { property string album: "" property string artist: "" + property bool av_connected: false + property int duration: 0 property int position: 0 - property string cover_art: "" - property string status: "" + property string status: "stopped" function time2str(value) { - return Qt.formatTime(new Date(value), 'mm:ss') + return Qt.formatTime(new Date(value), (value > 3600000) ? 'hh:mm:ss' : 'mm:ss') } } + Component.onCompleted : { + // Let the mediaplayer backend know we're ready for metadata events + mediaplayer.start() + + VehicleSignals.connect() + } + Connections { target: mediaplayer - onPlaylistChanged: { - playlist.clear() - - for (var i = 0; i < playlist.list.length; i++) { - var item = playlist.list[i] + onMetadataChanged: { + var track = metadata.track - playlist_model.append({ "index": item.index, "artist": item.artist ? item.artist : '', "title": item.title ? item.title : '' }) + if ('status' in metadata) { + player.status = metadata.status + } - if (item.selected) { - playlistview.currentIndex = i - } + if ('connected' in metadata) { + player.av_connected = metadata.connected } - } - onMetadataChanged: { - player.title = metadata.title - player.album = metadata.album - player.artist = metadata.artist + if (track) { + if ('image' in track) + return + player.title = track.title + player.album = track.album + player.artist = track.artist - if (metadata.duration) { - player.duration = metadata.duration - } + if ('duration' in track) + player.duration = track.duration - if (metadata.position) { - player.position = metadata.position + if ('index' in track) { + playlistview.currentIndex = track.index + } } - if (metadata.status) { - player.status = metadata.status + if ('position' in metadata) { + player.position = metadata.position } + } + } - if (metadata.image) { - player.cover_art = metadata.image - } + Connections { + target: VehicleSignals - playlistview.currentIndex = metadata.index + onConnected: { + VehicleSignals.authorize() } - } - API.BluetoothManager { - id: bluetooth - url: bindingAddress + onAuthorized: { + VehicleSignals.subscribe("Vehicle.Cabin.Infotainment.Media.Action") + } + + onSignalNotification: { + if (path === "Vehicle.Cabin.Infotainment.Media.Action") { + if (value == "SkipForward") { + mediaplayer.next() + } else if (value == "SkipBackward") { + mediaplayer.previous() + } else if (value == "NextSource") { + if (player.av_connected) + mediaplayer.connect() + else + mediaplayer.disconnect() + } + } + } } Timer { id: timer interval: 250 - running: (bluetooth.av_connected && bluetooth.state == "playing") + running: player.av_connected && player.status == "playing" repeat: true onTriggered: { - bluetooth.position = bluetooth.position + 250 + player.position = player.position + 250 } } - ListModel { - id: playlist_model - } + Item { + id: container + anchors.centerIn: parent + width: Window.width + height: Window.height + //scale: screenInfo.scale_factor() + scale: 1 ColumnLayout { anchors.fill: parent @@ -111,14 +141,13 @@ ApplicationWindow { Layout.preferredHeight: 1080 clip: true Image { - id: albumart anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom height: sourceSize.height * width / sourceSize.width fillMode: Image.PreserveAspectCrop - source: player.cover_art ? player.cover_art : '' - visible: bluetooth.av_connected == false + source: AlbumArt + visible: player.av_connected === false } Item { @@ -148,11 +177,10 @@ ApplicationWindow { //} ToggleButton { id: loop - visible: bluetooth.connected == false - //checked: player.loop_state + visible: player.av_connected === false offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg' onImage: './images/AGL_MediaPlayer_Loop_Active.svg' - onClicked: { mediaplayer.loop(checked) } + onClicked: { mediaplayer.loop(checked ? "playlist" : "off") } } } ColumnLayout { @@ -160,13 +188,13 @@ ApplicationWindow { Label { id: title Layout.alignment: Layout.Center - text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '') + text: player.title horizontalAlignment: Label.AlignHCenter verticalAlignment: Label.AlignVCenter } Label { Layout.alignment: Layout.Center - text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '') + text: player.artist horizontalAlignment: Label.AlignHCenter verticalAlignment: Label.AlignVCenter font.pixelSize: title.font.pixelSize * 0.6 @@ -176,28 +204,22 @@ ApplicationWindow { Slider { id: slider Layout.fillWidth: true - to: bluetooth.av_connected ? bluetooth.duration : player.duration - enabled: bluetooth.av_connected == false - value: bluetooth.av_connected ? bluetooth.position : player.position - function getPosition() { - if (bluetooth.av_connected) { - return player.time2str(bluetooth.position) - } - return player.time2str(player.position) - } + to: player.duration + enabled: player.av_connected === false + value: player.position Label { id: position anchors.left: parent.left anchors.bottom: parent.top font.pixelSize: 32 - text: slider.getPosition() + text: player.time2str(player.position) } Label { id: duration anchors.right: parent.right anchors.bottom: parent.top font.pixelSize: 32 - text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration) + text: player.time2str(player.duration) } onPressedChanged: mediaplayer.seek(value) } @@ -214,24 +236,11 @@ ApplicationWindow { id: previous offImage: './images/AGL_MediaPlayer_BackArrow.svg' onClicked: { - if (bluetooth.av_connected) { - bluetooth.sendMediaCommand("Previous") - bluetooth.position = 0 - } else { - mediaplayer.previous() - } + mediaplayer.previous() } } ImageButton { id: play - offImage: './images/AGL_MediaPlayer_Player_Play.svg' - onClicked: { - if (bluetooth.av_connected) { - bluetooth.sendMediaCommand("Play") - } else { - mediaplayer.play() - } - } states: [ State { when: player.status == "playing" @@ -239,48 +248,41 @@ ApplicationWindow { target: play offImage: './images/AGL_MediaPlayer_Player_Pause.svg' onClicked: { - player.status = "" mediaplayer.pause() } } }, State { - when: bluetooth.av_connected && bluetooth.state == "playing" + when: player.status != "playing" PropertyChanges { target: play - offImage: './images/AGL_MediaPlayer_Player_Pause.svg' - onClicked: bluetooth.sendMediaCommand("Pause") + offImage: './images/AGL_MediaPlayer_Player_Play.svg' + onClicked: mediaplayer.play() } } - ] } ImageButton { id: forward offImage: './images/AGL_MediaPlayer_ForwardArrow.svg' onClicked: { - if (bluetooth.av_connected) { - bluetooth.sendMediaCommand("Next") - } else { - mediaplayer.next() - } + mediaplayer.next() } } Item { Layout.fillWidth: true } ToggleButton { - visible: bluetooth.connected - checked: bluetooth.av_connected - offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg' - onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg' - + visible: true + checked: player.av_connected onClicked: { - if (bluetooth.av_connected) { - bluetooth.disconnect_profiles() - } else { - bluetooth.connect_profiles() - } + if (checked) + mediaplayer.connect() + else + mediaplayer.disconnect() + } + contentItem: Image { + source: player.av_connected ? './images/AGL_MediaPlayer_Bluetooth_Active.svg' : './images/AGL_MediaPlayer_Bluetooth_Inactive.svg' } } } @@ -295,14 +297,14 @@ ApplicationWindow { ListView { anchors.fill: parent id: playlistview - visible: bluetooth.av_connected == false + visible: player.av_connected === false clip: true header: Label { x: 50 text: 'PLAYLIST' opacity: 0.5 } - model: playlist_model + model: MediaplayerModel currentIndex: -1 delegate: MouseArea { @@ -333,7 +335,7 @@ ApplicationWindow { //} } onClicked: { - mediaplayer.picktrack(playlistview.model.get(index).index) + mediaplayer.picktrack(playlistview.model[index].index) } } @@ -345,3 +347,4 @@ ApplicationWindow { } } } +}