get next in queue to work
This commit is contained in:
parent
81225975f7
commit
520e18f8c8
1 changed files with 32 additions and 12 deletions
|
@ -10,7 +10,7 @@ angular.module('podcasts.services', ['podcasts.utilities', 'podcasts.queueList',
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
.service('player', ['db', 'url', '$timeout', function(db, url, $timeout) {
|
.service('player', ['db', 'url', '$timeout', 'feedItems', '$rootScope', function(db, url, $timeout, feedItems, $rootScope) {
|
||||||
var audio = new Audio();
|
var audio = new Audio();
|
||||||
audio.setAttribute("mozaudiochannel", "content");
|
audio.setAttribute("mozaudiochannel", "content");
|
||||||
var currentFeedItem = null;
|
var currentFeedItem = null;
|
||||||
|
@ -28,6 +28,9 @@ angular.module('podcasts.services', ['podcasts.utilities', 'podcasts.queueList',
|
||||||
|
|
||||||
function play(feedItem, $scope)
|
function play(feedItem, $scope)
|
||||||
{
|
{
|
||||||
|
console.log('playing: ' + feedItem.title);
|
||||||
|
var delayPlay = false;
|
||||||
|
|
||||||
if (feedItem) {
|
if (feedItem) {
|
||||||
currentFeedItem = feedItem;
|
currentFeedItem = feedItem;
|
||||||
var audioSrc;
|
var audioSrc;
|
||||||
|
@ -44,34 +47,51 @@ angular.module('podcasts.services', ['podcasts.utilities', 'podcasts.queueList',
|
||||||
updateSong(feedItem, $scope);
|
updateSong(feedItem, $scope);
|
||||||
|
|
||||||
if (feedItem.position) {
|
if (feedItem.position) {
|
||||||
|
delayPlay = true;
|
||||||
angular.element(audio).bind('canplay', function(event) {
|
angular.element(audio).bind('canplay', function(event) {
|
||||||
this.currentTime = feedItem.position;
|
this.currentTime = feedItem.position;
|
||||||
|
|
||||||
angular.element(this).unbind('canplay');
|
angular.element(this).unbind('canplay');
|
||||||
|
|
||||||
|
audio.play();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!delayPlay) {
|
||||||
audio.play();
|
audio.play();
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: handle save when feedItem is not passed in
|
// TODO: add something here for when audio is done to remove from queue and go to next song
|
||||||
angular.element(audio).bind('pause', function(event) {
|
audio.addEventListener("ended", function(event) {
|
||||||
feedItem.position = Math.floor(event.target.currentTime);
|
var nextFeedItemPromise = feedItems.getNextInQueue(feedItem);
|
||||||
|
console.log('got promise for next feed item');
|
||||||
|
$rootScope.$apply(nextFeedItemPromise.then(function(nextFeedItem) {
|
||||||
|
console.log('Got next Feed Item:');
|
||||||
|
console.log(nextFeedItem);
|
||||||
|
console.log(nextFeedItem.title);
|
||||||
|
play(nextFeedItem, $scope);
|
||||||
|
|
||||||
|
feedItem.queued = 0;
|
||||||
|
feedItem.position = 0;
|
||||||
|
db.put("feedItem", feedItem);
|
||||||
|
}, function(error) {
|
||||||
|
console.log('got Errror when fetching next feed item');
|
||||||
|
|
||||||
|
feedItem.queued = 0;
|
||||||
|
feedItem.position = 0;
|
||||||
db.put("feedItem", feedItem);
|
db.put("feedItem", feedItem);
|
||||||
|
}));
|
||||||
|
|
||||||
angular.element(this).unbind();
|
angular.element(this).unbind();
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: add something here for when audio is done to remove from queue and go to next song
|
//TODO: handle save when feedItem is not passed in
|
||||||
angular.element(audio).bind('ended', function(event) {
|
angular.element(audio).bind('pause', function(event) {
|
||||||
feedItem.queued = 0;
|
console.log('paused audio');
|
||||||
feedItem.position = 0;
|
feedItem.position = Math.floor(event.target.currentTime);
|
||||||
db.put("feedItem", feedItem);
|
db.put("feedItem", feedItem);
|
||||||
|
|
||||||
// start next item
|
|
||||||
// get next item from queue
|
|
||||||
play(nextFeedItem, $scope);
|
|
||||||
|
|
||||||
angular.element(this).unbind();
|
angular.element(this).unbind();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue