//playerDiv, sound, durationInMsec, visualizers, markerMap);
Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
-
+
//sound duration is in milliseconds because the soundmanager has that unit,
//player (according to timeside syntax) has durations in seconds
// newMarkerCallback must be either a string or a function, the necessary checks is done in Timeside.load
}
var onReadyWithImage = configObject.onReadyWithImage;
-
+
if(typeof onReadyWithImage === 'function'){
var onReadyWithImageNamespace = 'imgRefreshed.temp_'+new Date().getTime(); //get an unique namespace
this.bind(onReadyWithImageNamespace,function(data){
var soundOptions = sound;
if(sMan.canPlayURL(soundOptions.url)){ //this actually checks only if the url is well formed, not if the file is there
//check if we specified a valid sound duration, otherwise the sound must be loaded
-
+
sound = sMan.createSound(soundOptions);
}else{
this.soundErrorMsg = 'bad sound parameter (soundManager.canPlayURL returned false)';
this.playState = 0; //0: not playing, 1: loading, 2:buffering, 3 playing (sound heard)
//container is the div #player
-
+
this.getContainer = function(){
return container;
};
-
-
+
+
var sd = this.toSec(soundDurationInMsec);
this.getSoundDuration = function(){
return sd;
};
-
+
this.soundPosition = sound.position ? this.toSec(sound.position) : 0;
-
-
-
+
+
+
//
-
+
//initializing markermap and markerui
var map = new Timeside.classes.MarkerMap();
this.getMarkerMap = function(){
this.newMarker = newMarker;
}
}
-
+
//build the innerHTML as array, then join it. This is usually faster than string concatenation in some browsers.
//Note that the player image (see below) is not created now, however, if it was, it should be given a src
//as NOT specifying any src for image tags can be harmful,
"</div>"];
container.html(html.join(''));
-
+
var control = container.find('.ts-control');
//bind events to buttons:
//set sound position:
var oldSoundPosition = this.soundPosition;
this.soundPosition = newPositionInSeconds;
-
+
//resume playing if it was playing:
if(wasPlaying){
var player = this;
-
+
//delay a little bit the play resume, this might avoid fast pointer repositioning
//(it should not be the case, but it happens. why??)
setTimeout(function(){
//the value is in seconds
//markerCrossedOffsetMargin : 0.5,
play : function(){
-
+
if(this.soundErrorMsg){
alert(this.soundErrorMsg);
return false;
//together with this.soundErrorMsg != "", so we should have catch the case above
return false;
}
-
+
var fireOnMarkerPosition = function(seconds){}; //does nothing by default
var map = player.getMarkerMap();
data.currentSoundPosition = seconds;
data.nextMarkerTimeInterval = marker ? [offs-margin, offs+margin] : undefined;
player.fire('markerCrossed',data);
-
+
if(idx<len){
intervalUpperBound = offs+margin;
intervalLowerBound = offs-margin;
var sPosInMsec = player.toMsec(player.soundPosition);
var bufferingString = this.msgs.buffering;
var loadingString = this.msgs.loading;
-
+
var updateWaitBar = this.setWait;
//building immediately data events to be passed instead of bulding them in the loop whileplaying
var loadData = {
playState = this.playState = 1;
this.fire('playStateChanged',loadData);
}
-
+
var playOptions = {
-
+
position: sPosInMsec,
whileplaying: function(){
var sPos = this.position;
var buffering = this.isBuffering || typeof sPos != 'number' || sPos < sPosInMsec;
-
+
//var buffering = this.isBuffering; //this refers to the soundmanager sound obj
//Now, what are we doing here below? we could simply check whether is buffering or not..
//Unfortunately, when buffering some playState (isBuffering = false) are also fired, randomly
},
onfinish: function() {
-
+
//whileplaying is NOT called onsinfish. We must update the pointer:
//note that for small length sounds (wg, 5 secs) the pointer shifts abruptly from the last
//whileplaying position to the end. We tried with a setTimeout function but the visual effect is not
setWait: function(msg){
var wait = undefined;
-
+
wait = this.getWaitElement();
if(!wait || msg === undefined){
return;
}
var visible = wait.css('display') != 'none';
-
+
if(msg && !visible){
wait.show();
this.fire('waitShown');
}
},100);
},
-
+
resize: function() {
var height;
var container = this.getContainer();
-
+
var wave = container.find('.ts-wave');
height = wave.height();
var container = this.getContainer();
var imageC = container.find('.ts-image-container');
var image = imageC.find('.ts-image');
-
+
var size = this.getImageSize();
if(!imageNotYetCreated && image.attr('src')==imgSrc){
return;
}
-
+
var player= this;
-
+
if(imageNotYetCreated){
image = this.$J('<img/>');
}
this.isImgRefreshing = true;
this.fire('imgRefreshing');
image.attr('src', imgSrc);
-
+
},
getImageSize: function(){
var wave = this.getContainer().find('.ts-wave');
idx++;
}
}
-
+
if(idx< len){
offset = markers[idx].offset;
}
//TODO: think about if clearing or not: we assign some bindings in the constructor, too:
// map.clear();
// ruler.clear();
-
+
var rulerAdd = ruler.add;
-
+
if(markers){
//add markers to the map. No listeners associated to it (for the moment)
for(var i =0; i< markers.length; i++){
rulerAdd.apply(ruler,[marker.offset, i, marker.isEditable]);
});
}
-
+
//the function above calls map.add:
//add bindings when adding a marker:
map.bind('add',function(data){
});
//and now add a binding to the map when we move a marker:
-
+
map.bind('move', function(data){
var from = data.fromIndex;
var to = data.toIndex;
* MIT Licensed.
* (Inspired by base2 and Prototype)
*/
-
+
/*
* In few words: the lightest and most-comprehensive way to implement inhertance and OOP in javascript. Usages can be found below.
* Basically,
* this._super(); //!!!ERROR: methods defined in the init function don't have acces to _super
* }
* this.alert = function(){ //another public method, !!!WARNING: this will be put in the MyClass scope (NOT in the prototype)
- * alert('ok');
+ * alert('ok');
* }
* },
* count:0, //public property
* this._super(); //call the super constructor
* }
* alert: function(){ //override a method
- * this._super(); //call the super method, ie alerts 'no'. WARNING: However, as long as there is an alert written
+ * this._super(); //call the super method, ie alerts 'no'. WARNING: However, as long as there is an alert written
* //in the init method of the superclass (see above), THAT method will be called
* }
* });
// Populate our constructed prototype object
Class.prototype = prototype;
-
+
// Enforce the constructor to be what we expect
Class.constructor = Class;
//(ie, every instance has its own copy)
this.listenersMap={};
},
-
+
cssPrefix : 'ts-', //actually almost uneuseful, still here for backward compatibility with old code (TODO: remove?)
$J : jQuery, //reference to jQuery for faster lookup inside methods
$TU : Timeside.utils, //reference to Timeside variable for faster lookup inside methods
cb.apply(optionalThisArgInCallback,[data]);
};
}
-
+
if(listenersMap.hasOwnProperty(eventType)){
listenersMap[eventType].push(callback);
}else{
callbacks[i](dataArgument);
}
},
-
+
/*
*formats (ie returns a string representation of) a time which is in the form seconds,milliseconds (eg 07.6750067)
* formatArray is an array of strings which can be:
if(!(formatArray)){
formatArray = ['mm','ss'];
}
-
+
//marker offset is in float format second.decimalPart
var pInt = parseInt;
var round = Math.round;
time-=minutes*factor;
var seconds = pInt(time);
time-=seconds;
-
+
//here below the function to format a number
//ceilAsPowerOfTen is the ceil specifiedas integer indicating the relative power of ten
//(0: return the number as it is, 1: format as "0#" and so on)
//2) each(m, callback) iterates over the elements from m executing callback
//3) each(m,n,callback) iterates over the elements from m (inclusive) to n-1 (inclusive) executing callback
- //NOTE: writing each : function(startInclusive, endExclusive, callback) throws an error in chrome, as the last
+ //NOTE: writing each : function(startInclusive, endExclusive, callback) throws an error in chrome, as the last
//argument (even if it is a function) is a number. Why?????
//Anyway, we write the function arguments as empty
each : function(){
for(var i = startInclusive; i<endExclusive; i++){
callback(i,me[i]);
}
-
+
},
//clears the array and the events associated to it, ie removes all its elements and calls unbind(). Returns the array of the removed elements
s.onerror = function() {
Timeside.utils.flashFailed = true;
//end('SoundManager error. If your browser does not support HTML5, Flash player (version '+soundManager.flashVersion+'+) must be installed.\nIf flash is installed, try to:\n - Reload the page\n - Empty the cache (see browser preferences/options/tools) and reload the page\n - Restart the browser');
-
+
//and load all anyway:
loadAll();
};