Skip to content

Instantly share code, notes, and snippets.

@cesarandreu
Forked from elbuo8/app.js
Last active January 1, 2016 19:49
Show Gist options
  • Save cesarandreu/8193238 to your computer and use it in GitHub Desktop.
Save cesarandreu/8193238 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', '$q', function ($resource, $q) {
var getPlaylist = function(params){
var deferred = $q.defer();
$http
.get('http://hypem.com/playlist/'+params.playlist+'/all/json/'+params.pagenum+'/data.json')
.success(function(data){
deferred.resolve(data);
})
.error(function(data){
deferred.reject(data);
});
return deferred.promise;
};
return {
getPlaylist: getPlaylist
};
}])
.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})
.then(function(songs){
addToQueue(songs);
currentPage++;
})
.catch(function(err){
console.log('Error: ', err)
});
};
$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