All pastes #2104076 Raw Edit

Untitled

public text v1 · immutable
#2104076 ·published 2012-01-19 14:46 UTC
rendered paste body
// we have a set of functions

function play(){

}

function stop(){

}

function timeupdate(time){
	// based on the time we do whatever we want.
}



// when you have media, load jplayer and catch events:

$('#jplayer').jPlayer({
	ready: function () {
		$(this).jPlayer("setMedia", {
			mp3: url,
			oga: url.replace('.mp3', '.ogg')
		});
	},
	errorAlerts: true,
	supplied: "mp3, oga"
}).on($.jPlayer.event.play, function(e){
	play();
}).on($.jPlayer.event.pause, function(e){
	if( e.jPlayer.status.currentTime === 0 ){
		stop();	
	} else {
		pause();
	}
}).on($.jPlayer.event.ended, function(e){
		stop();	
}).on($.jPlayer.event.timeupdate, function(e){
	timeupdate(e.jPlayer.status.currentTime);
});


// when we don't have media we simulate media

// by first firing play for the sake of it:
play();

// we set a duration of the lecture:
duration = 9876543;

// then we simulate timeupdates every 250 ms
var currentTime = 0
var timer = setInterval(function(){
	if( currentTime > duration ){
		stop();
		clearInterval(timer);
		return true;
	}
	currentTime+=250;
	timeupdate(currentTime);

}, 250);