1
0
mirror of https://github.com/danbee/mpd-client synced 2025-03-04 08:39:09 +00:00

Update currently playing track and allow playing of track with click.

This commit is contained in:
Dan Barber 2014-03-25 12:38:57 +00:00
parent 6dd77fe971
commit 453d351633
4 changed files with 16 additions and 6 deletions

View File

@ -1,13 +1,19 @@
mpdClient.controller('queue', function ($scope, api, serverEvents) { mpdClient.controller('queue', function ($scope, api, serverEvents) {
$scope.queueSongs = api.getQueue().query() $scope.queueSongs = api.getQueue().query()
$scope.updateQueue = function(data) { $scope.updateQueue = function (data) {
$scope.queueSongs = data $scope.queueSongs = data
} }
$scope.playTrack = function(id) { $scope.playTrack = api.playTrack
console.log(id)
$scope.updatePlaying = function (songid) {
$scope.queueSongs.forEach(function (song) {
if (song.id == songid) { song.playing = true }
else if (song.playing == true) { song.playing = false }
})
} }
$scope.$on('update:queue', function (evt, data) { $scope.updateQueue(data) }) $scope.$on('update:queue', function (evt, data) { $scope.updateQueue(data) })
$scope.$on('update:status', function (evt, data) { $scope.updatePlaying(data.songid) })
}) })

View File

@ -7,6 +7,10 @@ mpdClient.factory('api', function ($rootScope, $http, $resource) {
$http({ method: 'PUT', url: apiUrl + '/control/' + command }) $http({ method: 'PUT', url: apiUrl + '/control/' + command })
}, },
playTrack: function (pos) {
$http({ method: 'PUT', url: apiUrl + '/control/play', params: { pos: pos } })
},
getStatus: function () { getStatus: function () {
return $http({ method: 'GET', url: apiUrl + '/status' }) return $http({ method: 'GET', url: apiUrl + '/status' })
}, },

View File

@ -2,9 +2,9 @@ mpdClient.factory('serverEvents', function ($rootScope) {
var events = new EventSource('/api/stream') var events = new EventSource('/api/stream')
events.onmessage = function(e) { events.onmessage = function (e) {
response = JSON.parse(e.data); response = JSON.parse(e.data);
$rootScope.$apply(function() { $rootScope.$apply(function () {
$rootScope.$broadcast('update:' + response.type, response.data) $rootScope.$broadcast('update:' + response.type, response.data)
}) })
} }

View File

@ -4,7 +4,7 @@
<h1>Queue</h1> <h1>Queue</h1>
</header> </header>
<ol class="songs"> <ol class="songs">
<li ng-repeat="song in queueSongs" ng-class="{ playing: song.playing }"> <li ng-repeat="song in queueSongs" ng-click="playTrack(song.pos)" ng-class="{ playing: song.playing }">
<p class="title">{{ song.title }}</p> <p class="title">{{ song.title }}</p>
<p class="artist">{{ song.artist }}</p> <p class="artist">{{ song.artist }}</p>
<p class="length">{{ song.length | formatLength }}</p> <p class="length">{{ song.length | formatLength }}</p>