X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=app%2FMediaPlayer.qml;h=cdd9368c5cfa0d29ca9d6697c40586f605ad8b6f;hb=e8d39ebb00189c47e38992e3923acb4df7a81cc9;hp=fbd889c444051de0d2c27495c2ca5a24ff68181b;hpb=52918332b8e7860e63ec59774bcce2d5ecabb53b;p=apps%2Fmediaplayer.git diff --git a/app/MediaPlayer.qml b/app/MediaPlayer.qml index fbd889c..cdd9368 100644 --- a/app/MediaPlayer.qml +++ b/app/MediaPlayer.qml @@ -14,105 +14,91 @@ * 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.11 + import AGL.Demo.Controls 1.0 -import MediaPlayer 1.0 -import 'api' as API ApplicationWindow { id: root + width: container.width * container.scale + height: container.height * container.scale + Item { - id: bluetooth - property bool connected: false - property string state + id: player + + property string title: "" + property string album: "" + property string artist: "" + + property bool av_connected: false - property string artist - property string title property int duration: 0 property int position: 0 - property int pos_offset: 0 - function disableBluetooth() { - bluetooth.artist = '' - bluetooth.title = '' - bluetooth.duration = 0 - bluetooth.position = 0 - bluetooth.pos_offset = 0 - bluetooth.connected = false - } - } + property string status: "stopped" - API.LightMediaScanner { - id: binding - url: bindingAddress + function time2str(value) { + return Qt.formatTime(new Date(value), (value > 3600000) ? 'hh:mm:ss' : 'mm:ss') + } } Connections { - target: dbus + target: mediaplayer - onProcessPlaylistHide: { - playlistview.visible = false - player.stop() - } + onMetadataChanged: { + var track = metadata.track - onProcessPlaylistShow: { - playlistview.visible = true - bluetooth.disableBluetooth() - } + if ('status' in metadata) { + player.status = metadata.status + } - onDisplayBluetoothMetadata: { - if (avrcp_artist) - bluetooth.artist = avrcp_artist - if (avrcp_title) - bluetooth.title = avrcp_title - bluetooth.duration = avrcp_duration - bluetooth.pos_offset = 0 - } + if ('connected' in metadata) { + player.av_connected = metadata.connected + } - onUpdatePlayerStatus: { - bluetooth.connected = true - bluetooth.state = status - } + if (track) { + if ('image' in track) + return + player.title = track.title + player.album = track.album + player.artist = track.artist - onUpdatePosition: { - slider.value = current_position - bluetooth.position = current_position - } - } + if ('duration' in track) + player.duration = track.duration - MediaPlayer { - id: player - audioRole: MediaPlayer.MusicRole - autoLoad: true - playlist: playlist + if ('index' in track) { + playlistview.currentIndex = track.index + } + } - property bool is_bluetooth: false - function time2str(value) { - return Qt.formatTime(new Date(value), 'mm:ss') + if ('position' in metadata) { + player.position = metadata.position + } } - onPositionChanged: slider.value = player.position } Timer { id: timer interval: 250 - running: (bluetooth.connected && bluetooth.state == "playing") + running: player.av_connected && player.status == "playing" repeat: true onTriggered: { - bluetooth.position = dbus.getCurrentPosition() - bluetooth.pos_offset - slider.value = bluetooth.position + player.position = player.position + 250 } } - Playlist { - id: playlist - playbackMode: random.checked ? Playlist.Random : loop.checked ? Playlist.Loop : Playlist.Sequential - } - + Item { + id: container + anchors.centerIn: parent + width: Screen.width + height: Screen.height + //scale: screenInfo.scale_factor() + scale: 1 ColumnLayout { anchors.fill: parent @@ -122,14 +108,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.metaData.coverArtImage ? player.metaData.coverArtImage : '' - visible: bluetooth.connected == false + source: AlbumArt + visible: player.av_connected === false } Item { @@ -151,17 +136,18 @@ ApplicationWindow { Layout.fillHeight: true Row { spacing: 20 - ToggleButton { - id: random - visible: bluetooth.connected == false - offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg' - onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg' - } + //ToggleButton { + // id: random + // visible: bluetooth.connected == false + // offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg' + // onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg' + //} ToggleButton { id: loop - visible: bluetooth.connected == false + visible: player.av_connected === false offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg' onImage: './images/AGL_MediaPlayer_Loop_Active.svg' + onClicked: { mediaplayer.loop(checked ? "playlist" : "off") } } } ColumnLayout { @@ -169,13 +155,13 @@ ApplicationWindow { Label { id: title Layout.alignment: Layout.Center - text: bluetooth.title ? bluetooth.title : (player.metaData.title ? player.metaData.title : '') + text: player.title horizontalAlignment: Label.AlignHCenter verticalAlignment: Label.AlignVCenter } Label { Layout.alignment: Layout.Center - text: bluetooth.artist ? bluetooth.artist : (player.metaData.contributingArtist ? player.metaData.contributingArtist : '') + text: player.artist horizontalAlignment: Label.AlignHCenter verticalAlignment: Label.AlignVCenter font.pixelSize: title.font.pixelSize * 0.6 @@ -185,29 +171,24 @@ ApplicationWindow { Slider { id: slider Layout.fillWidth: true - to: bluetooth.connected ? bluetooth.duration : player.duration - enabled: bluetooth.connected == false - function getPosition() { - if (bluetooth.connected && bluetooth.position) { - 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.connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration) + text: player.time2str(player.duration) } - onPressedChanged: player.seek(value) + onPressedChanged: mediaplayer.seek(value) } RowLayout { Layout.fillHeight: true @@ -222,63 +203,54 @@ ApplicationWindow { id: previous offImage: './images/AGL_MediaPlayer_BackArrow.svg' onClicked: { - if (bluetooth.connected) { - bluetooth.pos_offset = dbus.getCurrentPosition() - dbus.processQMLEvent("Previous") - } else { - playlist.previous() - } + mediaplayer.previous() } } ImageButton { id: play - offImage: './images/AGL_MediaPlayer_Player_Play.svg' - onClicked: { - if (bluetooth.connected) { - dbus.processQMLEvent("Play") - } else { - player.play() - } - } states: [ State { - when: player.playbackState === MediaPlayer.PlayingState + when: player.status == "playing" PropertyChanges { target: play offImage: './images/AGL_MediaPlayer_Player_Pause.svg' - onClicked: player.pause() + onClicked: { + mediaplayer.pause() + } } }, State { - when: bluetooth.connected && bluetooth.state == "playing" + when: player.status != "playing" PropertyChanges { target: play - offImage: './images/AGL_MediaPlayer_Player_Pause.svg' - onClicked: dbus.processQMLEvent("Pause") + offImage: './images/AGL_MediaPlayer_Player_Play.svg' + onClicked: mediaplayer.play() } } - ] } ImageButton { id: forward offImage: './images/AGL_MediaPlayer_ForwardArrow.svg' onClicked: { - if (bluetooth.connected) { - dbus.processQMLEvent("Next") - } else { - playlist.next() - } + mediaplayer.next() } } Item { Layout.fillWidth: true } ToggleButton { - enabled: false - checked: bluetooth.connected - offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg' - onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg' + visible: true + checked: player.av_connected + onClicked: { + 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' + } } } } @@ -289,22 +261,18 @@ ApplicationWindow { Layout.fillHeight: true Layout.preferredHeight: 407 - PlaylistWithMetadata { - id: playlistmodel - source: playlist - } - ListView { anchors.fill: parent id: playlistview + visible: player.av_connected === false clip: true header: Label { x: 50 text: 'PLAYLIST' opacity: 0.5 } - model: playlistmodel - currentIndex: playlist.currentIndex + model: MediaplayerModel + currentIndex: -1 delegate: MouseArea { id: delegate @@ -314,12 +282,6 @@ ApplicationWindow { anchors.fill: parent anchors.leftMargin: 50 anchors.rightMargin: 50 - Image { - source: model.coverArt - fillMode: Image.PreserveAspectFit - Layout.preferredWidth: delegate.height - Layout.preferredHeight: delegate.height - } ColumnLayout { Layout.fillWidth: true Label { @@ -329,19 +291,18 @@ ApplicationWindow { Label { Layout.fillWidth: true text: model.artist - color: '#66FF99' + color: '#00ADDC' font.pixelSize: 32 } } - Label { - text: player.time2str(model.duration) - color: '#66FF99' - font.pixelSize: 32 - } + //Label { + // text: player.time2str(model.duration) + // color: '#00ADDC' + // font.pixelSize: 32 + //} } onClicked: { - playlist.currentIndex = model.index - player.play() + mediaplayer.picktrack(playlistview.model[index].index) } } @@ -353,3 +314,4 @@ ApplicationWindow { } } } +}