' + ( isSupport ? $( '
' ),
theAudio = isSupport ? thePlayer.find( 'audio' ) : thePlayer.find( 'embed' ), theAudio = theAudio.get( 0 );
if( isSupport )
{
thePlayer.find( 'audio' ).css( { 'width': 0, 'height': 0, 'visibility': 'hidden' } );
thePlayer.append( '
' );
var theBar = thePlayer.find( '.' + cssClass.bar ),
barPlayed = thePlayer.find( '.' + cssClass.barPlayed ),
barLoaded = thePlayer.find( '.' + cssClass.barLoaded ),
timeCurrent = thePlayer.find( '.' + cssClass.timeCurrent ),
timeDuration = thePlayer.find( '.' + cssClass.timeDuration ),
volumeButton = thePlayer.find( '.' + cssClass.volumeButton ),
volumeAdjuster = thePlayer.find( '.' + cssClass.volumeAdjust + ' > div' ),
volumeDefault = 0,
adjustCurrentTime = function( e )
{
theRealEvent = isTouch ? e.originalEvent.touches[ 0 ] : e;
theAudio.currentTime = Math.round( ( theAudio.duration * ( theRealEvent.pageX - theBar.offset().left ) ) / theBar.width() );
},
adjustVolume = function( e )
{
theRealEvent = isTouch ? e.originalEvent.touches[ 0 ] : e;
theAudio.volume = Math.abs( ( theRealEvent.pageY - ( volumeAdjuster.offset().top + volumeAdjuster.height() ) ) / volumeAdjuster.height() );
},
updateLoadBar = function()
{
var interval = setInterval( function()
{
if( theAudio.buffered.length < 1 ) return true;
barLoaded.width( ( theAudio.buffered.end( 0 ) / theAudio.duration ) * 100 + '%' );
if( Math.floor( theAudio.buffered.end( 0 ) ) >= Math.floor( theAudio.duration ) ) clearInterval( interval );
}, 100 );
};
var volumeTestDefault = theAudio.volume, volumeTestValue = theAudio.volume = 0.111;
if( Math.round( theAudio.volume * 1000 ) / 1000 == volumeTestValue ) theAudio.volume = volumeTestDefault;
else thePlayer.addClass( cssClass.noVolume );
timeDuration.html( '…' );
timeCurrent.html( secondsToTime( 0 ) );
theAudio.addEventListener( 'loadeddata', function()
{
updateLoadBar();
timeDuration.html( $.isNumeric( theAudio.duration ) ? secondsToTime( theAudio.duration ) : '…' );
volumeAdjuster.find( 'div' ).height( theAudio.volume * 100 + '%' );
volumeDefault = theAudio.volume;
});
theAudio.addEventListener( 'timeupdate', function()
{
timeCurrent.html( secondsToTime( theAudio.currentTime ) );
barPlayed.width( ( theAudio.currentTime / theAudio.duration ) * 100 + '%' );
});
theAudio.addEventListener( 'volumechange', function()
{
volumeAdjuster.find( 'div' ).height( theAudio.volume * 100 + '%' );
if( theAudio.volume > 0 && thePlayer.hasClass( cssClass.muted ) ) thePlayer.removeClass( cssClass.muted );
if( theAudio.volume <= 0 && !thePlayer.hasClass( cssClass.muted ) ) thePlayer.addClass( cssClass.muted );
localStorage.setItem('vol', theAudio.volume);
});
theAudio.addEventListener( 'ended', function()
{
thePlayer.removeClass( cssClass.playing ).addClass( cssClass.stopped );
apNext ();
});
theBar.on( eStart, function( e )
{
adjustCurrentTime( e );
theBar.on( eMove, function( e ) { adjustCurrentTime( e ); } );
})
.on( eCancel, function()
{
theBar.unbind( eMove );
});
volumeButton.on( 'click', function()
{
if( thePlayer.hasClass( cssClass.muted ) )
{
thePlayer.removeClass( cssClass.muted );
theAudio.volume = volumeDefault;
}
else
{
thePlayer.addClass( cssClass.muted );
volumeDefault = theAudio.volume;
theAudio.volume = 0;
}
return false;
});
volumeAdjuster.on( eStart, function( e )
{
adjustVolume( e );
volumeAdjuster.on( eMove, function( e ) { adjustVolume( e ); } );
})
.on( eCancel, function()
{
volumeAdjuster.unbind( eMove );
});
}
else thePlayer.addClass( cssClass.mini );
thePlayer.addClass( isAutoPlay ? cssClass.playing : cssClass.stopped );
thePlayer.find( '.' + cssClass.playPause ).on( 'click', function()
{
var currentClickSong = $(this).parent().parent();
var currentClickSongClass = currentClickSong.attr('class');
if( thePlayer.hasClass( cssClass.playing ) )
{
$( this ).attr( 'title', params.strPlay ).find( 'a' ).html( params.strPlayI );
thePlayer.removeClass( cssClass.playing ).addClass( cssClass.stopped );
isSupport ? theAudio.pause() : theAudio.Stop();
$('.js-stop').removeClass('js-stop').addClass('js-paused');
}
else
{
$( this ).attr( 'title', params.strPause ).find( 'a' ).html( params.strPauseI );
thePlayer.addClass( cssClass.playing ).removeClass( cssClass.stopped );
isSupport ? theAudio.play() : theAudio.Play();
$('.js-paused').removeClass('js-paused').addClass('js-stop');
}
return false;
});
$this.replaceWith( thePlayer );
});
return this;
};
})( jQuery, window, document );
/* end */