html5 audio duration,HTML5 Audio Player Duration Showing Nan

I just started to learn HTML5 and was going through HTML5 Audio player using JQuery. I coded a player with Playlist, everything works fine except the Duration with help of which my input range slider doesn't works. When I debugged I found that my duration is showing me NAN. I am setting the duration after the song is initialized.

Here is my JS code

jQuery(document).ready(function() {

container = $('.container');

playList = $('#playlist');

playListSong = $('#playlist li');

cover = $('.cover');

play = $('#play');

pause = $('#pause');

mute = $('#mute');

muted = $('#muted');

close = $('#close');

song = new Audio('music/Whistle-Flo-Rida-Mp3-Download.mp3','music/Whistle-Flo-Rida-Mp3-Download.mp3');

var canPlay = song.canPlayType('audio/mpeg;');

if (canPlay) {

song.type= 'audio/mpeg';

song.src= 'music/Whistle-Flo-Rida-Mp3-Download.mp3';

}

playListSong.click(function(){

$('#close').trigger('click');

window["song"] = new Audio('music/'+$(this).html()+'.mp3','music/'+$(this).html()+'.mp3');

$('#play').trigger('click');

});

play.live('click', function(e) {

e.preventDefault();

song.play();

//cover.attr("title", song.duration);

$(this).replaceWith('k');

$('#close').fadeIn(300);

$('#seek').attr('max',song.duration);

});

pause.live('click', function(e) {

e.preventDefault();

song.pause();

$(this).replaceWith('d');

});

mute.live('click', function(e) {

e.preventDefault();

song.volume = 0;

$(this).replaceWith('o');

});

muted.live('click', function(e) {

e.preventDefault();

song.volume = 1;

$(this).replaceWith('o');

});

$('#close').click(function(e) {

e.preventDefault();

container.removeClass('containerLarge');

cover.removeClass('coverLarge');

song.pause();

song.currentTime = 0;

$('#pause').replaceWith('d');

$('#close').fadeOut(300);

});

$("#seek").bind("change", function() {

song.currentTime = $(this).val();

$("#seek").attr("max", song.duration);

});

song.addEventListener('timeupdate',function (){

curtime = parseInt(song.currentTime, 10);

$("#seek").attr("value", curtime);

});

});

When I click on playlist song, the duration is always NAN but by default I have set one song, and directly on page load when I clicked Play button then the duration works fine. It never works for playlist songs.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值