<input type="file" name="audio" id="voice_file" style="display: inline-block;" accept="audio/mp3">
<audio id="audio" controls autoplay="" style="display: none; "></audio>
//上传
$("#voice_file").on("change", function () {
var objUrl = upload_file(this.files[0]);
if (objUrl.code == 1) {
$('#video_url').val(objUrl.data.photo)
$('.imgWrap').html('<audio height="150" src="'+objUrl.data.photo+'" controls id="video_control"></audio>')
var audioFile = get_object_uRL(this.files[0]);
$("#audio").attr("src", audioFile);
$("#audio")[0].pause();
$("#audio").show();
getTime();
} else {
layer.msg(objUrl.msg, {icon: 5});
}
});
//获取时长
function getTime() {
setTimeout(function () {
var duration = $("#audio")[0].duration;
if(isNaN(duration)){
getTime();
}else{
console.info("该歌曲的总时间为:"+$("#audio")[0].duration+"秒")
$('#ma_time').val(duration)
}
}, 10);
}