为什么我的音频不能用Chrome播放?

时间:2016-01-13 15:02:13

标签: php html audio

我试图在html桌面通知旁边运行音频,我收到通知但声音没有播放。

真正让我感觉的是它有时播放声音,但通常不会播放声音。

这是我的代码:

PHP:

        $checkTickets2 = mysqli_query($con, "SELECT * FROM techs WHERE needsNotify='1'");
        $tcheckTickets2 = mysqli_num_rows($checkTickets2);

        if($tcheckTickets2 > 0) {
            try { 
                $db = new PDO($dsn, $user, $password); 
            } catch (PDOException $e) { 
                echo 'Connection failed: ' . $e->getMessage(); 
            }

            $st = $db->prepare('SELECT * FROM techs WHERE needsNotify=1'); 
            $st->execute(); 

            $result = $st->fetchAll(PDO::FETCH_ASSOC); 

            foreach($result as $d){ 
                if(strcmp($d['Name'],$_SESSION['Name']) == 0) {
                    echo $d['UniqueID'] . "<br/>"; 
                    $id = $d['UniqueID']; 
                    sendNotify(); //this runs, and works properly
                    sendSound(); //I do not get any sound
                    sleep(3);
                    $st = $db->prepare("UPDATE techs SET needsNotify='0' WHERE UniqueID=$id");
                    $st->execute(); 
                }
            }           
        }

这是我的sendSound函数:

           function sendSound() { ?>
            <audio class="audio" controls autoplay>
              <source src="images/notif.mp3" type="audio/mpeg">
             <!-- <embed height="50" width="100" src="images/notif.mp3"> NOT NECESSARY -->
            </audio>
        <? }

0 个答案:

没有答案