$(function () {
   setTimeout(audioUpload,1000);
    function audioUpload(){
        var $audioUpload = $("#audioUpload"),
            $uploaderFiles = $("#uploaderFiles");
        $audioUpload.on("change",function (e) {
            console.log('mp3')
            files = e.target.files;
            // 如果没有选中文件，直接返回
            if (files.length === 0) {
                return;
            }
            for (var i = 0, len = files.length; i < len; ++i) {
                var file = files[i];
                var reader = new FileReader();
                var fileType = file.type;
                var base64;
                reader.onload = function (e) {
                    $.showLoading("上传中");
                    var FormDatas = new FormData();
                    FormDatas.append("file", file);
                    //这里实现上传
                    $.ajax({
                        url: uploadUrl,
                        type: 'POST',
                        data: FormDatas,
                        contentType: false,
                        processData: false,
                        success: function (res) {
                            if (res.code === "200"){
                                console.log(res,'res')
                                var str =`
                                    <div class="audio_a" style="position: relative;margin-bottom: 87px" fullURL="${res.data.fullURL}">
                                        <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary delete_audio">删除</a>
                                        <div id="aplayer${res.data.fileExt}"></div>
                                    </div>`;
                                $('.mp3_text .title_style').after(str);
                                $('.Sound_m').hide();
                                $.toast('上传成功');
                                $.hideLoading();
                                APlayers(res.data.fileExt,res.data.fullURL,res.data.fileName);
                            }else {
                                $.toast("上传失败",'forbidden');
                                $.hideLoading();
                            }
                        },
                        error:function () {
                            $.toast("上传失败,请检查网络！",'forbidden');
                            $.hideLoading();
                        }
                    })

                };
                reader.readAsDataURL(file);
            }
        });
        function APlayers(id,url,name) {
            const ap = new APlayer({
                container: document.getElementById('aplayer'+id),
                mini: false,
                audio: [{
                    name: name,
                    url: url
                }]
            });
        }
    }
});