通知无法在iPad和Android设备上播放声音

时间:2018-07-12 14:32:18

标签: javascript php ajax laravel-5

我正在使用需要在创建新商店时发出声音通知的系统。我对AJAX部件没问题,当我在PC中打开系统时声音正常,但是当我尝试在装有Chrome的iPad上尝试时声音不起作用和Safri,即使是在装有Google Chrome的Android设备中,我的代码也不行,还是其他设备不支持该代码?

我的代码:

if(typeof(EventSource) !== "undefined") {

var source = new EventSource($('meta[name="base_url"]').attr('content') +'/notification_ajax');
var audio = new Audio('assets/file.mp3');

source.onmessage = function(event) {

    var myarr = event.data.split(",");

    if(parseInt(myarr[1]) !=  parseInt(myarr[0])){
        audio.play()
        var url = $('meta[name="base_url"]').attr('content') +'/update_file';
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $.post(url,
            {old_count: myarr[1]
            },
            function (data) {

            })

    };
}}

谢谢!

0 个答案:

没有答案