Skip to content

Commit

Permalink
Speaker v0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
tanelt committed Mar 25, 2012
1 parent e4e7d35 commit 9738a13
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/public/js/app_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ $(function() {
}

ms.player.pause();
//ms.player.pause();
ms.player.resource = jukebox.Manager.getPlayableResource(track.resources);
for (var s in track) {
ms.player.settings[s] = track[s];
Expand All @@ -134,7 +133,7 @@ $(function() {

playTrack: function(spriteid, offset) {
var track = ms.loadedTrack;
if (!track || track && !track.spritemap[spriteid]) {
if (!ms.player || !track || track && !track.spritemap[spriteid]) {
return;
}
var pos = ms.player.settings["spritemap"][spriteid].start;
Expand All @@ -149,10 +148,12 @@ $(function() {
$("#loading").hide();
// Update treack time left
ms.trackInterval = setInterval(function() {
$("#time").html(ms.formatDuration(ms.player.context));
if (ms.player.context.duration === ms.player.context.currentTime) {
clearInterval(ms.trackInterval);
ms.trigger("stop");
if (ms.player) {
$("#time").html(ms.formatDuration(ms.player.context));
if (ms.player.context.duration === ms.player.context.currentTime) {
clearInterval(ms.trackInterval);
ms.stopTrack();
}
}
}, 1000);
//console.log('playTrack '+spriteid+' '+(ms.timesync.getTime())+'');
Expand All @@ -161,9 +162,13 @@ $(function() {
stopTrack: function(){
$("#speaker-animation").hide();
clearInterval(ms.trackInterval);
ms.player.pause();

// Reload
ms.player && ms.player.pause();
ms.payloadQueue = [];

$("#speaker-on").show();
$("#speaker-animation").hide();

// Fallback to reload
document.location.reload();
},

Expand Down Expand Up @@ -217,11 +222,6 @@ $(function() {
// Add payload to queue
ms.on('payload', ms.onQueuePayload);

// Play and stop request
ms.on('play', ms.playTrack);
ms.on('pause', ms.pauseTrack);
ms.on('stop', ms.stopTrack);

ms.on("speakerCount", ms.updateSpeakerCount);
ms.on("loadedCount", ms.updateLoadedCount);

Expand All @@ -230,7 +230,7 @@ $(function() {
ms.errors = 0;

setInterval(function(){
if(ms.playing){
if(ms.playing && ms.player){
diff = (ms.player.context.currentTime-ms.playOffset)*1000 - (ms.timesync.getTime()-ms.playTime) + ms.deviceLatency;
console.log('latency '+(diff-ms.deviceLatency));
if(diff > 0 || diff < -400){
Expand Down Expand Up @@ -265,4 +265,4 @@ $(function() {

$("#playBtn").on('mousedown', _.bind(ms.startPlayer, ms));
$("#playBtn").on('touchstart', _.bind(ms.startPlayer, ms));
}, ms);
}, ms);

0 comments on commit 9738a13

Please sign in to comment.