+ 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
+
+ bluetooth.connected = true
+ mediaplayer.pause()
+
+ //NOTE: This hack is here for when MediaPlayer is started
+ // with an existing connection.
+ bluetooth.av_connected = item.AVPConnected == "True"
+ }
+ }
+ if (!address)
+ bluetooth.connected = false
+ else
+ bluetooth.deviceAddress = address
+ }
+
+ onDeviceUpdatedEvent: {
+ var metadata = data.Metadata
+
+ if (data.Connected == "False")
+ return
+
+ 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 (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