X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=app%2FMediaPlayer.qml;h=f6beafdbf82b01855bcf109431da88334c331006;hb=refs%2Fchanges%2F25%2F22325%2F2;hp=7dfaf06a09b2f57ddbdab08b91b242372dbb982e;hpb=04ae48a26ece6b6e21010f3d187f173837f99c23;p=apps%2Fmediaplayer.git diff --git a/app/MediaPlayer.qml b/app/MediaPlayer.qml index 7dfaf06..f6beafd 100644 --- a/app/MediaPlayer.qml +++ b/app/MediaPlayer.qml @@ -22,6 +22,9 @@ import AGL.Demo.Controls 1.0 ApplicationWindow { id: root + width: container.width * container.scale + height: container.height * container.scale + Item { id: player @@ -29,162 +32,67 @@ 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: "stopped" function time2str(value) { - return Qt.formatTime(new Date(value), 'mm:ss') - } - } - - Item { - id: bluetooth - - property string deviceAddress: "" - property bool connected: false - property bool av_connected: false - - property int position: 0 - property int duration: 0 - - property string artist: "" - property string title: "" - property string state: "stopped" - - // AVRCP Target UUID - property string avrcp_uuid: "0000110e-0000-1000-8000-00805f9b34fb" - - function connect_profiles() { - var address = bluetooth.deviceAddress; - bluetooth_connection.connect(address, "a2dp") - bluetooth_connection.connect(address, "avrcp") - } - - function disconnect_profiles() { - var address = bluetooth.deviceAddress; - bluetooth_connection.disconnect(address, "a2dp") - bluetooth_connection.disconnect(address, "avrcp") - } - - function set_avrcp_controls(cmd) { - bluetooth_connection.set_avrcp_controls(bluetooth.deviceAddress, cmd) + return Qt.formatTime(new Date(value), (value > 3600000) ? 'hh:mm:ss' : 'mm:ss') } } Connections { - target: bluetooth_connection - - onDeviceListEvent: { - var address = "" - for (var i = 0; i < data.list.length; i++) { - var item = data.list[i] - if (item.Connected == "True" && item.UUIDs.indexOf(bluetooth.avrcp_uuid) >= 0) { - address = item.Address + target: mediaplayer - bluetooth.connected = true - mediaplayer.pause() + onMetadataChanged: { + var track = metadata.track - //NOTE: This hack is here for when MediaPlayer is started - // with an existing connection. - bluetooth.av_connected = item.AVPConnected == "True" - } + if ('status' in metadata) { + player.status = metadata.status } - if (!address) - bluetooth.connected = false - else - bluetooth.deviceAddress = address - } - - onDeviceUpdatedEvent: { - var metadata = data.Metadata - if (data.Connected == "False") - return - - if (!bluetooth.av_connected && data.AVPConnected == "True") { - mediaplayer.pause() - player.status = "stopped" + if ('connected' in metadata) { + player.av_connected = metadata.connected } - bluetooth.connected = data.Connected == "True" - bluetooth.av_connected = data.AVPConnected == "True" - bluetooth.deviceAddress = data.Address - - if ('Position' in metadata) - bluetooth.position = metadata.Position - - if ('Duration' in metadata) - bluetooth.duration = metadata.Duration - - if ('Status' in metadata) - bluetooth.state = metadata.Status - - if ('Artist' in metadata) - bluetooth.artist = metadata.Artist - - if ('Title' in metadata) - bluetooth.title = metadata.Title - } - } - - Connections { - target: mediaplayer - - onPlaylistChanged: { - playlist_model.clear(); - - for (var i = 0; i < playlist.list.length; i++) { - var item = playlist.list[i] - - playlist_model.append({ "index": item.index, "artist": item.artist ? item.artist : '', "title": item.title ? item.title : '' }) + if (track) { + if ('image' in track) + return + player.title = track.title + player.album = track.album + player.artist = track.artist + player.duration = track.duration - if (item.selected) { - playlistview.currentIndex = i + if ('index' in track) { + playlistview.currentIndex = track.index } } - } - - onMetadataChanged: { - player.title = metadata.title - player.album = metadata.album - player.artist = metadata.artist - - if (metadata.duration) { - player.duration = metadata.duration - } - if (metadata.position) { + if ('position' in metadata) { player.position = metadata.position } - - if (metadata.status) { - player.status = metadata.status - } - - if (metadata.image) { - player.cover_art = metadata.image - } - - playlistview.currentIndex = metadata.index } } 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: 1080 + height: 1487 + scale: screenInfo.scale_factor() ColumnLayout { anchors.fill: parent @@ -194,14 +102,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 { @@ -231,11 +138,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 { @@ -243,13 +149,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 @@ -259,28 +165,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) } @@ -297,51 +197,29 @@ ApplicationWindow { id: previous offImage: './images/AGL_MediaPlayer_BackArrow.svg' onClicked: { - if (bluetooth.av_connected) { - bluetooth.set_avrcp_controls("Previous") - bluetooth.position = 0 - } else { - mediaplayer.previous() - } + mediaplayer.previous() } } ImageButton { id: play states: [ State { - when: !bluetooth.av_connected && player.status == "playing" + when: player.status == "playing" PropertyChanges { target: play offImage: './images/AGL_MediaPlayer_Player_Pause.svg' onClicked: { - player.status = "stopped" mediaplayer.pause() } } }, State { - when: bluetooth.av_connected && bluetooth.state == "playing" - PropertyChanges { - target: play - offImage: './images/AGL_MediaPlayer_Player_Pause.svg' - onClicked: bluetooth.set_avrcp_controls("Pause") - } - }, - State { - when: !bluetooth.av_connected && player.status != "playing" + when: player.status != "playing" PropertyChanges { target: play offImage: './images/AGL_MediaPlayer_Player_Play.svg' onClicked: mediaplayer.play() } - }, - State { - when: bluetooth.av_connected && bluetooth.state != "playing" - PropertyChanges { - target: play - offImage: './images/AGL_MediaPlayer_Player_Play.svg' - onClicked: bluetooth.set_avrcp_controls("Play") - } } ] } @@ -349,28 +227,23 @@ ApplicationWindow { id: forward offImage: './images/AGL_MediaPlayer_ForwardArrow.svg' onClicked: { - if (bluetooth.av_connected) { - bluetooth.set_avrcp_controls("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' } } } @@ -385,14 +258,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 { @@ -423,7 +296,7 @@ ApplicationWindow { //} } onClicked: { - mediaplayer.picktrack(playlistview.model.get(index).index) + mediaplayer.picktrack(playlistview.model[index].index) } } @@ -435,3 +308,4 @@ ApplicationWindow { } } } +}