簡體   English   中英

iPad 和 iPhone 中沒有播放聲音

[英]Sound not playing in iPad and iPhone

我用 Django 建立了一個網站,但在 Apple 設備中播放聲音時遇到問題。 聲音在 Windows 計算機、Android 設備和 Mac 計算機上正常播放。

但是當您使用 iPhone 或 iPad 訪問網站時,聲音不會播放。

下一個是我用來播放聲音的Javascript。

我不知道可能是哪個問題。

function playSound(){
    if(sound.paused){
        repetitions--;
        sound.pause();
        if(repetitions >= 0){
            sound_btn.firstChild.textContent = '';
            sound.play();   
            sound_btn.classList.toggle('btn-primary');
            sound_btn.classList.toggle('btn-danger');
            sound_btn.firstChild.classList.toggle('bi-volume-up-fill');
            sound_btn.firstChild.classList.toggle('bi-soundwave');
        }   
    }
}

function audioFinish(){
    sound.currentTime = 0;
    sound_btn.classList.toggle('btn-primary');
    sound_btn.classList.toggle('btn-danger');
    sound_btn.firstChild.classList.toggle('bi-volume-up-fill');
    sound_btn.firstChild.classList.toggle('bi-soundwave');
    sound_btn.firstChild.textContent = repetitions.toString();
    if(repetitions == 0){
        sound_btn.classList.remove('btn-primary');
        sound_btn.classList.remove('btn-danger');
        sound_btn.classList.add('btn-secondary');
        sound_btn.disabled = true;
        sound_btn.firstChild.classList.remove('bi-soundwave');
        sound_btn.firstChild.classList.remove('bi-volume-up-fill');
        sound_btn.firstChild.classList.add('bi-volume-mute-fill');
    }
}

sound_btn.addEventListener("click", playSound, false);
sound.addEventListener("ended", audioFinish, false);

這可能是由於瀏覽器與 JS 聲音 API 的兼容性。 如果您在使用它的設備上使用 chrome 或 Firefox 但在蘋果設備上使用 safari,這將是您的問題。

Refer to this for ios specifics: https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/PlayingandSynthesizingSounds/PlayingandSynthesizingSounds.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM