|
|
@ -26,7 +26,28 @@ _
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
"use strict";
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
var Player = Backbone.View.extend({
|
|
|
|
if (!_.isFunction(Array.prototype.shuffle)) {
|
|
|
|
|
|
|
|
Array.prototype.shuffle = function() {
|
|
|
|
|
|
|
|
var len = this.length
|
|
|
|
|
|
|
|
, i = len
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( len === 0 ) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (i--) {
|
|
|
|
|
|
|
|
var p = parseInt(Math.random()*len, 10);
|
|
|
|
|
|
|
|
var t = this[i];
|
|
|
|
|
|
|
|
this[i] = this[p];
|
|
|
|
|
|
|
|
this[p] = t;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Player = Backbone.View.extend({
|
|
|
|
elViewport: null
|
|
|
|
elViewport: null
|
|
|
|
, $elViewport: null
|
|
|
|
, $elViewport: null
|
|
|
|
|
|
|
|
|
|
|
@ -46,19 +67,35 @@ _
|
|
|
|
|
|
|
|
|
|
|
|
, _stateAudio: null
|
|
|
|
, _stateAudio: null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
, _state: null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
, _states: {
|
|
|
|
|
|
|
|
stopped: 0
|
|
|
|
|
|
|
|
, loading: 1
|
|
|
|
|
|
|
|
, playing: 2
|
|
|
|
|
|
|
|
, paused: 3
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
, events: {
|
|
|
|
, events: {
|
|
|
|
//"click #add-friend": "showPrompt",
|
|
|
|
//"click #add-friend": "showPrompt",
|
|
|
|
"click div:first-child > a.buttonPrev": "__buttonPrevious"
|
|
|
|
"click div:first-child > a.buttonPrev":
|
|
|
|
, "click div:first-child > a.buttonNext": "__buttonNext"
|
|
|
|
"__buttonPrevious"
|
|
|
|
, "click div:first-child > a.buttonPlay": "__buttonPlayPause"
|
|
|
|
, "click div:first-child > a.buttonNext":
|
|
|
|
|
|
|
|
"__buttonNext"
|
|
|
|
|
|
|
|
, "click div:first-child > a.buttonPlay":
|
|
|
|
|
|
|
|
"__buttonPlayPause"
|
|
|
|
// Volume Down
|
|
|
|
// Volume Down
|
|
|
|
, "click div:first-child > .playerVolumeWrapper > a:first-child": "__buttonVolumeDown"
|
|
|
|
, "click div:first-child > .playerVolumeWrapper > a:first-child":
|
|
|
|
|
|
|
|
"__buttonVolumeDown"
|
|
|
|
// Volume Up
|
|
|
|
// Volume Up
|
|
|
|
, "click div:first-child > .playerVolumeWrapper > a:last-child": "__buttonVolumeUp"
|
|
|
|
, "click div:first-child > .playerVolumeWrapper > a:last-child":
|
|
|
|
|
|
|
|
"__buttonVolumeUp"
|
|
|
|
// Volume click
|
|
|
|
// Volume click
|
|
|
|
, "click div:first-child > .playerVolumeWrapper > input": "__buttonVolumeClick"
|
|
|
|
, "click div:first-child > .playerVolumeWrapper > input":
|
|
|
|
|
|
|
|
"__buttonVolumeClick"
|
|
|
|
// Seek input
|
|
|
|
// Seek input
|
|
|
|
, "click div:last-child > .playerProgressWrapper > progress": "__buttonSeek"
|
|
|
|
, "click div:last-child > .playerProgressWrapper > progress":
|
|
|
|
|
|
|
|
"__buttonSeek"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
, initialize: function (options) {
|
|
|
|
, initialize: function (options) {
|
|
|
@ -66,8 +103,12 @@ _
|
|
|
|
;
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
_.bindAll(this
|
|
|
|
_.bindAll(this
|
|
|
|
|
|
|
|
// Public
|
|
|
|
|
|
|
|
, "setPlayIndex"
|
|
|
|
, "setRandomState"
|
|
|
|
, "setRandomState"
|
|
|
|
, "setRepeatState"
|
|
|
|
, "setRepeatState"
|
|
|
|
|
|
|
|
, "playItem"
|
|
|
|
|
|
|
|
// Events
|
|
|
|
, "__buttonPlayPause"
|
|
|
|
, "__buttonPlayPause"
|
|
|
|
, "__buttonNext"
|
|
|
|
, "__buttonNext"
|
|
|
|
, "__buttonPrevious"
|
|
|
|
, "__buttonPrevious"
|
|
|
@ -75,7 +116,9 @@ _
|
|
|
|
, "__buttonVolumeDown"
|
|
|
|
, "__buttonVolumeDown"
|
|
|
|
, "__buttonVolumeClick"
|
|
|
|
, "__buttonVolumeClick"
|
|
|
|
, "__buttonSeek"
|
|
|
|
, "__buttonSeek"
|
|
|
|
, "_createWebAudio"
|
|
|
|
// Private
|
|
|
|
|
|
|
|
, "_waCreate"
|
|
|
|
|
|
|
|
, "_waBindEvents"
|
|
|
|
, "__waStateChanged"
|
|
|
|
, "__waStateChanged"
|
|
|
|
, "_playerEnded"
|
|
|
|
, "_playerEnded"
|
|
|
|
, "_playerLoading"
|
|
|
|
, "_playerLoading"
|
|
|
@ -102,6 +145,8 @@ _
|
|
|
|
|
|
|
|
|
|
|
|
that.$el.append(that.elViewport);
|
|
|
|
that.$el.append(that.elViewport);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
that._waCreate();
|
|
|
|
|
|
|
|
|
|
|
|
return that;
|
|
|
|
return that;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -112,20 +157,39 @@ _
|
|
|
|
var that = this
|
|
|
|
var that = this
|
|
|
|
;
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
that._playIndex = index;
|
|
|
|
|
|
|
|
that._playCursor = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (that._stateRandom) {
|
|
|
|
|
|
|
|
that.setRandomState(that._stateRandom);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return that._playIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
, setRandomState: function (random) {
|
|
|
|
, setRandomState: function (random) {
|
|
|
|
var that = this
|
|
|
|
var that = this
|
|
|
|
;
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (random === true) {
|
|
|
|
|
|
|
|
that._playIndex.shuffle();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Set cursor back to the item that was playing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return that._stateRandom = random;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
, setRepeatState: function (random) {
|
|
|
|
, setRepeatState: function (repeat) {
|
|
|
|
var that = this
|
|
|
|
var that = this
|
|
|
|
;
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return that._stateRepeat = repeat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
, playItem: function (item) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* EVENTS
|
|
|
|
* EVENTS
|
|
|
|
**/
|
|
|
|
**/
|
|
|
@ -175,10 +239,15 @@ _
|
|
|
|
* PRIVATE
|
|
|
|
* PRIVATE
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
// Audio Player
|
|
|
|
// Audio Player
|
|
|
|
, _createWebAudio: function () {
|
|
|
|
, _waCreate: function () {
|
|
|
|
var that = this
|
|
|
|
var that = this
|
|
|
|
;
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return that.webAudio = new WebAudio();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
, _waBindEvents: function () {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
, __waStateChanged: function () {
|
|
|
|
, __waStateChanged: function () {
|
|
|
|