mediaelementJS播放器在暂停时淡出音量的最佳方法是什么?
设置media.volume = 0.0可以正常工作,然后使用 jQuery 为播放侦听器设置音量动画。但是对于暂停侦听器,在我有机会淡出音频之前,音频会暂停。
var volumeSet = 0.8; //Default volume
var player = new MediaElementPlayer('video,audio',{
success: function (media, domObject) {
//This works fine
media.addEventListener('play', function() {
media.volume = 0;
$('video,audio').animate({volume: volumeSet}, 1000, "swing");
}, false)
//This 'works', but lags as its needed to be re-played after pause
media.addEventListener('pause', function(e) {
if (media.volume>0) {
volumeSet = media.volume;
media.play();
$('video,audio').animate({volume: 0.0}, 1000, "swing", function(){
media.pause();
});
}
}, false);
}
});