<div ng-app="myApp" ng-controller="Playlist"> Now playing: <input type="text" ng-model="playlist.nowPlaying"/> <ol> <li ng-repeat="sound in playlist.sounds" ng-controller="Sound"> <b>{{sound.title}}</b> <button ng-click="play()">▶</button> <audio src="http://api.soundcloud.com/tracks/{{sound.id}}/stream?client_id=YOUR_CLIENT_ID" playing="$index + 1 == playlist.nowPlaying"> </audio> </li> </ol> </div>
angular.module('myApp', []). controller('Playlist', function($scope) { $scope.playlist = { sounds: [ { id: 19822913, title: 'Sad Trombone' }, { id: 19358868, title: 'Reckoning Song' }, { id: 82841736, title: 'Every James Hetfield "Yea"... ever.' } ] } }). controller('Sound', function($scope) { $scope.play = function() { $scope.playlist.nowPlaying = $scope.$index + 1 } }). directive('playing', function() { return function(scope, element, attr) { scope.$watch(attr.playing, function(value) { if (value) { element[0].play() } else { element[0].pause() } }) } })