import QtQuick 2.6
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.0
-import QtMultimedia 5.6
import AGL.Demo.Controls 1.0
-import 'api' as API
ApplicationWindow {
id: root
- API.MediaPlayer {
+ width: container.width * container.scale
+ height: container.height * container.scale
+
+ Item {
id: player
- url: bindingAddress
+
+ property string title: ""
+ 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')
+ }
}
- API.BluetoothManager {
- id: bluetooth
- url: bindingAddress
+ Connections {
+ target: mediaplayer
+
+ onMetadataChanged: {
+ var track = metadata.track
+
+ if ('status' in metadata) {
+ player.status = metadata.status
+ }
+
+ if ('connected' in metadata) {
+ player.av_connected = metadata.connected
+ }
+
+ if ('position' in metadata) {
+ player.position = metadata.position
+ }
+
+ if (track) {
+ if ('image' in track) {
+ player.cover_art = track.image
+ }
+
+ player.title = track.title
+ player.album = track.album
+ player.artist = track.artist
+ player.duration = track.duration
+
+ if ('index' in track) {
+ playlistview.currentIndex = track.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
- }
+ Item {
+ id: container
+ anchors.centerIn: parent
+ width: 1080
+ height: 1487
+ scale: screenInfo.scale_factor()
ColumnLayout {
anchors.fill: parent
height: sourceSize.height * width / sourceSize.width
fillMode: Image.PreserveAspectCrop
source: player.cover_art ? player.cover_art : ''
- visible: bluetooth.av_connected == false
+ visible: player.av_connected === false
}
Item {
//}
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: { player.loop(checked) }
+ onClicked: { mediaplayer.loop(checked) }
}
}
ColumnLayout {
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
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: player.seek(value)
+ onPressedChanged: mediaplayer.seek(value)
}
RowLayout {
Layout.fillHeight: true
id: previous
offImage: './images/AGL_MediaPlayer_BackArrow.svg'
onClicked: {
- if (bluetooth.av_connected) {
- bluetooth.sendMediaCommand("Previous")
- bluetooth.position = 0
- } else {
- player.previous()
- }
+ mediaplayer.previous()
}
}
ImageButton {
id: play
- offImage: './images/AGL_MediaPlayer_Player_Play.svg'
- onClicked: {
- if (bluetooth.av_connected) {
- bluetooth.sendMediaCommand("Play")
- } else {
- player.play()
- }
- }
states: [
State {
- when: player.running === true
+ when: player.status == "playing"
PropertyChanges {
target: play
offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
- onClicked: player.pause()
+ onClicked: {
+ player.status = "stopped"
+ 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 {
- player.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()
}
+ offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
+ onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
}
}
}
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: MediaplayerModel
currentIndex: -1
delegate: MouseArea {
//}
}
onClicked: {
- player.pick_track(playlistview.model.get(index).index)
- player.play()
+ mediaplayer.picktrack(playlistview.model[index].index)
}
}
}
}
}
+}