import QtQuick.Controls 2.0
import QtMultimedia 5.6
import AGL.Demo.Controls 1.0
-import MediaPlayer 1.0
import 'api' as API
ApplicationWindow {
id: root
- API.LightMediaScanner {
- id: binding
- url: bindingAddress
- }
+ Item {
+ id: player
- API.BluetoothManager {
- id: bluetooth
- url: bindingAddress
- }
+ property string title: ""
+ property string album: ""
+ property string artist: ""
- MediaPlayer {
- id: player
- audioRole: MediaPlayer.MusicRole
- autoLoad: true
- playlist: playlist
+ property int duration: 0
+ property int position: 0
+
+ property string cover_art: ""
+ property string status: ""
function time2str(value) {
return Qt.formatTime(new Date(value), 'mm:ss')
}
}
+ 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 (item.selected) {
+ playlistview.currentIndex = i
+ }
+ }
+ }
+
+ onMetadataChanged: {
+ player.title = metadata.title
+ player.album = metadata.album
+ player.artist = metadata.artist
+
+ if (metadata.duration) {
+ player.duration = metadata.duration
+ }
+
+ if (metadata.position) {
+ player.position = metadata.position
+ }
+
+ if (metadata.status) {
+ player.status = metadata.status
+ }
+
+ if (metadata.image) {
+ player.cover_art = metadata.image
+ }
+
+ playlistview.currentIndex = metadata.index
+ }
+ }
+
+ API.BluetoothManager {
+ id: bluetooth
+ url: bindingAddress
+ }
+
Timer {
id: timer
interval: 250
repeat: true
onTriggered: {
bluetooth.position = bluetooth.position + 250
- slider.value = bluetooth.position
}
}
- Playlist {
- id: playlist
- playbackMode: random.checked ? Playlist.Random : loop.checked ? Playlist.Loop : Playlist.Sequential
+ ListModel {
+ id: playlist_model
}
-
ColumnLayout {
anchors.fill: parent
Item {
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: player.cover_art ? player.cover_art : ''
+ visible: bluetooth.av_connected == false
}
Item {
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
+ //checked: player.loop_state
offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
+ onClicked: { mediaplayer.loop(checked) }
}
}
ColumnLayout {
Label {
id: title
Layout.alignment: Layout.Center
- text: bluetooth.av_connected ? bluetooth.title : (player.metaData.title ? player.metaData.title : '')
+ text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '')
horizontalAlignment: Label.AlignHCenter
verticalAlignment: Label.AlignVCenter
}
Label {
Layout.alignment: Layout.Center
- text: bluetooth.av_connected ? bluetooth.artist : (player.metaData.contributingArtist ? player.metaData.contributingArtist : '')
+ text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '')
horizontalAlignment: Label.AlignHCenter
verticalAlignment: Label.AlignVCenter
font.pixelSize: title.font.pixelSize * 0.6
font.pixelSize: 32
text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
}
- onPressedChanged: player.seek(value)
+ onPressedChanged: mediaplayer.seek(value)
}
RowLayout {
Layout.fillHeight: true
bluetooth.sendMediaCommand("Previous")
bluetooth.position = 0
} else {
- playlist.previous()
+ mediaplayer.previous()
}
}
}
if (bluetooth.av_connected) {
bluetooth.sendMediaCommand("Play")
} else {
- player.play()
+ mediaplayer.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: {
+ player.status = ""
+ mediaplayer.pause()
+ }
}
},
State {
if (bluetooth.av_connected) {
bluetooth.sendMediaCommand("Next")
} else {
- playlist.next()
+ mediaplayer.next()
}
}
}
Layout.fillHeight: true
Layout.preferredHeight: 407
- PlaylistWithMetadata {
- id: playlistmodel
- source: playlist
- }
-
ListView {
anchors.fill: parent
id: playlistview
text: 'PLAYLIST'
opacity: 0.5
}
- model: playlistmodel
- currentIndex: playlist.currentIndex
+ model: playlist_model
+ currentIndex: -1
delegate: MouseArea {
id: delegate
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 {
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.get(index).index)
}
}