forked from adriengibrat/jQuery-SoundManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.playable.ui.simple.js
77 lines (77 loc) · 2.99 KB
/
jquery.playable.ui.simple.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*!
* jQuery Sound Manager Simple UI
* http://github.com/adriengibrat/jQuery-SoundManager
*
* Copyright (c) 2009 Adrien Gibrat
* Dual licensed under the MIT and GPL licenses.
* http://opensource.org/licenses/mit-license.php
*/
(function($){
if ( ! $.playable )
return;
$.playable.events.push( 'whileloading', 'whileplaying' );
$.extend( true, $.playable, {
css : {
ui : 'ui',
timing : 'timing',
elapsed : 'elapsed',
total : 'total',
progress : 'progress',
loading : 'loading',
position : 'position',
searching : 'searching'
},
formatTime : function( ms ) {
var ns = Math.floor( ms / 1000 ),
m = Math.floor( ns / 60 ),
s = ns - m * 60 ;
return m + ':' + ( s < 10 ? '0' + s : s );
},
ui : {
simple : function() {
$( this )
.prepend( '<span class="' + $.playable.css.ui + ' ' + $.playable.css.timing + '"><span class="' + $.playable.css.elapsed + '"></span><span class="' + $.playable.css.total + '"></span></span>' )
.append( '<span class="' + $.playable.css.ui + ' ' + $.playable.css.progress + '"><span class="' + $.playable.css.loading + '"></span><span class="' + $.playable.css.position + '"></span></span>' )
.bind( 'onstop.playable', function(){
$( '.' + $.playable.css.elapsed + ', .' + $.playable.css.total, this ).empty();
} )
.bind( 'whileloading.playable', function( event, sound ){
$( '.' + $.playable.css.loading, this ).width( sound.bytesLoaded / sound.bytesTotal * 100 + '%' );
} )
.bind( 'whileplaying.playable', function( event, sound ){
$( '.' + $.playable.css.position, this ).width( sound.position / sound.durationEstimate * 100 + '%' );
$( '.' + $.playable.css.elapsed, this ).html( $.playable.formatTime( sound.position ) );
$( '.' + $.playable.css.total, this ).html( ' / ' + $.playable.formatTime( sound.durationEstimate ) );
} )
.find( '.' + $.playable.css.ui )
.bind( 'click.playable', function() { return false; } )
.filter( '.' + $.playable.css.progress )
.bind( 'mousedown.playable', function( event ) {
var progress = $( this ).addClass( $.playable.css.searching ),
position = progress.find( '.' + $.playable.css.position ),
left = progress.offset().left,
width = progress.width(),
sound = progress.parent().data( 'playable' );
$.playable.searching = true;
sound.pause();
$( document )
.bind( 'mousemove.playable', function( event ) {
var x = Math.max( 0, Math.min( event.clientX - left, width ) );
position.width( x );
sound.setPosition( x / width * sound.durationEstimate );
return false;
} )
.bind( 'mouseup.playable', function() {
$.playable.searching = false;
if ( progress.removeClass( $.playable.css.searching ).parent().hasClass( $.playable.css.playing ) )
sound.resume();
$( this ).unbind( 'mousemove.playable mouseup.playable' );
return false;
} )
.trigger( { type: 'mousemove', clientX: event.clientX } );
return false;
} );
}
}
});
})(jQuery);