Files
dss/static/js/app/lib/audioController.js
2014-05-14 22:10:58 +01:00

128 lines
4.5 KiB
JavaScript
Executable File

// Generated by CoffeeScript 1.4.0
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
define(['app', 'marionette', 'vent', 'utils', 'soundmanager2', 'peneloplay'], function(App, Marionette, vent, utils, soundManager, peneloplay) {
var AudioController;
AudioController = (function(_super) {
__extends(AudioController, _super);
function AudioController() {
this.mixInit = __bind(this.mixInit, this);
return AudioController.__super__.constructor.apply(this, arguments);
}
AudioController.prototype.initialize = function(options) {
console.log("AudioController: initialize");
this.listenTo(vent, 'mix:init', this.mixInit);
this.listenTo(vent, 'mix:play', this.mixPlay);
this.listenTo(vent, 'mix:pause', this.mixPause);
this.listenTo(vent, 'mix:resume', this.mixResume);
this.listenTo(vent, 'playing:destroy', this.playingDestroy);
this.listenTo(vent, 'live:play', this.livePlay);
this.listenTo(vent, 'live:pause', this.livePause);
return soundManager.setup({
url: com.podnoms.settings.staticUrl + '/swf/sm/',
onready: function() {
vent.trigger('peneloplay:ready');
return console.log("Sound manager ready!");
},
debugFlash: com.podnoms.smDebugMode,
preferFlash: false,
defaultOptions: {
volume: com.podnoms.settings.volume
}
});
};
AudioController.prototype.setupPlayer = function(el, url) {
return peneloplay.setupPlayer(el, url);
};
AudioController.prototype.setupPlayerEl = function(el) {
peneloplay.setupPlayer(el);
return peneloplay.setupUIWidgets();
};
AudioController.prototype.mixInit = function(model, el) {
var _this = this;
console.log("AudioController: mixInit");
this.id = model.get('id');
this.duration = model.get("duration");
peneloplay.stopPlaying();
return $.getJSON("/ajax/mix_stream_url/" + this.id + "/", function(data) {
console.log("Setting up player: ", data.stream_url);
_this.setupPlayer(el, data.stream_url);
peneloplay.startPlaying({
success: function() {
vent.trigger("mix:play", model);
vent.trigger("live:stop");
utils.checkPlayCount();
},
error: function() {
utils.showWarning("Ooops", "Error playing mix. If you have a flash blocker, please disable it for this site. Otherwise, do please try again.");
}
});
com.podnoms.storage.setItem("now_playing", _this.id);
});
};
AudioController.prototype.isPlayingId = function(id) {
return id === this.id;
};
AudioController.prototype.getMixState = function() {
return peneloplay.getMixState();
};
AudioController.prototype.mixPlay = function() {
console.log("AudioController: mixPlay");
return peneloplay.resume();
};
AudioController.prototype.mixPause = function() {
console.log("AudioController: mixPause");
return peneloplay.pause();
};
AudioController.prototype.mixResume = function() {
console.log("AudioController: mixResume");
return peneloplay.resume();
};
AudioController.prototype.playingDestroy = function() {
return peneloplay.stopPlaying();
};
AudioController.prototype.livePlay = function() {
console.log("AudioController: livePlay");
vent.trigger('mix:stop');
return peneloplay.playLive({
success: function() {
console.log("Live stream started");
return vent.trigger('live:started');
}
});
};
AudioController.prototype.livePause = function() {
console.log("AudioController: livePause");
return peneloplay.stopLive({
success: function() {
console.log("Live stream started");
return vent.trigger('live:stopped');
}
});
};
return AudioController;
})(Marionette.Controller);
return AudioController;
});
}).call(this);