在iOS中花费太多时间

时间:2018-09-19 06:47:15

标签: jquery mobile

我正在尝试在一个网站中创建MP3播放器,它打开每个浏览器的速度太快,仅iPhone播放MP3文件占用了太多的加载时间。在Mac中,它也能正常工作。是否可以在iPhone Safari浏览器中加载快速MP3文件?

<script>
    $(document).ready(function() {
        $('.default_hide').hide();
    });

    function play1(ele) {
        var vall = $(ele).val();
        var id = $(ele).data("id");

        $(".default_show").each(function(index) {
            if (index == id) {
                if (vall == "Play") {
                    if ($('#audio' + index).attr('src') == "") {
                        $.ajax({
                            url: '/wp-admin/admin-ajax.php',
                            type: "post",
                            data: {
                                action: 'audio_link',
                                audio_id: id
                            },
                            success: function(data) {
                                //console.log(data);
                                $('#audio' + index).attr('src', data);
                                $('#audio' + index).attr('preload', 'auto');
                                //                                              $('#audio'+index).attr('autobuffer');                                               

                                $('#audio' + index).get(0).load();
                                //                              $('#audio'+index).get(0).play();
                                document.getElementById("audio" + index).play();
                                $(".songplay" + index).val("Pause");
                            }

                        });
                    } else {
                        document.getElementById("audio" + index).play();
                        $(".songplay" + index).val("Pause");
                    }

                    // document.getElementById("audio"+index).play();
                    // $(".songplay"+index).val("Pause");
                } else {
                    document.getElementById("audio" + index).pause();
                    $(".songplay" + index).val("Play");
                }
                // if($(this).val() == "Pause"){
                //  document.getElementById("audio"+index).pause();
                //  $(this).val("Play");
                // }
            } else {
                document.getElementById("audio" + index).pause();
                $(".songplay" + index).val("Play");
            }
        });
    }

    function seektimeupdate(num) {
        var dur = document.getElementById("audio" + num);
        var nt = dur.currentTime * (100 / dur.duration);
        var seek = document.getElementById("seekslider" + num);
        seek.value = nt;
        var curmins = Math.floor(dur.currentTime / 60);
        var cursecs = Math.floor(dur.currentTime - curmins * 60);
        var durmins = Math.floor(dur.duration / 60);
        var dursecs = Math.floor(dur.duration - durmins * 60);
        if (cursecs < 10) {
            cursecs = "0" + cursecs;
        }
        if (dursecs < 10) {
            dursecs = "0" + dursecs;
        }
        if (curmins < 10) {
            curmins = "0" + curmins;
        }
        if (durmins < 10) {
            durmins = "0" + durmins;
        }
        if (isNaN(durmins)) {
            var durmins = 0;
        }
        if (isNaN(dursecs)) {
            var dursecs = 0;
        }
        document.getElementById("curtimetext" + num).innerHTML = curmins + ":" + cursecs;
        document.getElementById("durtimetext" + num).innerHTML = durmins + ":" + dursecs;

    }

    function seek(num) {
        var seek = document.getElementById("seekslider" + num);
        var check = document.getElementById("audio" + num);
        seekto = check.duration * (seek.value / 100);
        check.currentTime = seekto;
    }
</script>

0 个答案:

没有答案