Skip to content

Commit

Permalink
Wait for the playlist to complete before OK.
Browse files Browse the repository at this point in the history
  • Loading branch information
angelnu committed Dec 30, 2016
1 parent 09ded0b commit de0fc09
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
38 changes: 29 additions & 9 deletions examples/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function connectToDevice(host, callback) {
preloadTime : 3,
startTime : 1,
activeTrackIds : [],
playbackDuration: 4,
playbackDuration: 2,
media: {
contentId: "http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/BigBuckBunnyAudio.mp4",
contentType: "audio/mpeg",
Expand All @@ -35,7 +35,7 @@ function connectToDevice(host, callback) {
preloadTime : 3,
startTime : 2,
activeTrackIds : [],
playbackDuration: 4,
playbackDuration: 2,
media: {
contentId: "http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/ElephantsDreamAudio.mp4",
contentType: "audio/mpeg",
Expand All @@ -47,7 +47,7 @@ function connectToDevice(host, callback) {
preloadTime : 3,
startTime : 3,
activeTrackIds : [],
playbackDuration: 4,
playbackDuration: 2,
media: {
contentId: "http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/ForBiggerBlazesAudio.mp4",
contentType: "audio/mpeg",
Expand All @@ -58,9 +58,22 @@ function connectToDevice(host, callback) {

console.log('app "%s" launched, loading medias...', player.session.displayName);

player.on('status', function(status) {
player.on('status', gotStatus);

//Done re-ordering?
var isDone = false;

function gotStatus(status) {
console.log('status broadcast = %s', util.inspect(status)," ");
});
if (
isDone,
status.idleReason == "FINISHED" &&
status.loadingItemId === undefined)
{
console.log("Done!");
callback(0);
}
}

// loads multiple items
player.queueLoad(
Expand All @@ -84,7 +97,7 @@ function connectToDevice(host, callback) {
preloadTime : 4,
startTime : 8,
activeTrackIds : [],
playbackDuration: 4,
playbackDuration: 2,
media: {
contentId: "http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/ForBiggerEscapesAudio.mp4",
contentType: "audio/mpeg",
Expand All @@ -104,6 +117,10 @@ function connectToDevice(host, callback) {
return;
};
console.log(util.inspect(status));
//Get status before we modify the title bellow
player.getStatus(function (err, status){
gotStatus(status);
});
player.queueRemove([2],{currentItemId:0}, function(err, status) {
console.log("Removed from QUEUE");
if (err) {
Expand All @@ -120,7 +137,7 @@ function connectToDevice(host, callback) {
preloadTime : 4,
startTime : 4,
activeTrackIds : [],
playbackDuration: 4,
playbackDuration: 2,
media: {
contentId: "http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/ForBiggerEscapesAudio.mp4",
contentType: "audio/mpeg",
Expand Down Expand Up @@ -149,8 +166,11 @@ function connectToDevice(host, callback) {
return;
};
console.log(util.inspect(status));
console.log("Done!");
callback(0); //OK
//Get status - check that the title from itemId=4 has been modified
player.getStatus(function (err, status){
gotStatus(status);
isDone = true;
});
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/queueTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var queueExample = require("../examples/queue");
describe('Queue', function() {
it('dynamic playlist changes', function(done) {
this.timeout(20000);
this.timeout(60000); //It usually takes 25 seconds
queueExample(done);
});
});

0 comments on commit de0fc09

Please sign in to comment.