Skip to content

Instantly share code, notes, and snippets.

@elbuo8
Created December 31, 2013 05:47
Show Gist options
  • Save elbuo8/8193124 to your computer and use it in GitHub Desktop.
Save elbuo8/8193124 to your computer and use it in GitHub Desktop.
angular.module('HypeM', ['ionic', 'ngResource', 'ngRoute'])
.config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'partials/player.html',
controller: 'PlayerCtrl'
}).
when('/latest', {
templateUrl: 'partials/player.html',
controller: 'PlayerCtrl'
}).
otherwise({ redirectTo: '/' });
}])
.service('Playlist', ['$resource', function ($resource) {
return $resource('http://hypem.com/playlist/:playlist/all/json/:pagenum/data.json',
{}, {getPlaylist: {method:'GET', params:{playlist:'popular', pagenum: '1'}, responseType:'json', cache:true}});
}])
.controller('PlayerCtrl', ['$scope','Playlist', '$routeParams', '$document', function ($scope, Playlist, $routeParams, $document) {
var addToQueue = function(songs) {
for (var key in songs) {
if (songs.hasOwnProperty(key) && angular.isObject(songs[key])) {
queue.push(songs[key]);
}
}
console.log(queue);
};
var getPlaylist = function () {
Playlist.getPlaylist({playlist: $routeParams.playlist || 'popular', pagenum: currentPage}, function(songs) {
addToQueue(songs);
currentPage++;
});
};
$scope.playerControl = function () {
if (isPlaying) {
audio.play();
} else {
audio.pause();
}
};
$scope.nextSong = function () {
//audio.src = queue[currentSongIdx++]
};
var isPlaying = false;
var currentSongIdx = 0;
var queue = [];
var currentPage = 1;
var audio = $document.find('player');
//init
getPlaylist();
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment