简体   繁体   English

HTML5音频播放器适用于safari / Chrome,但不适用于iPhone

[英]HTML5 Audio player works on safari/Chrome, but not iPhone

I've got an HTML5 audio player that works on Safari on the PC, but doesn't seem to work on (my) iPhone (4). 我有一个HTML5音频播放器可以在PC上运行Safari,但似乎不适用于(我的)iPhone(4)。 Here's the code: 这是代码:

`    
function loadPlayer() {
    var audioPlayer = new Audio();
    audioPlayer.controls="controls";
    audioPlayer.addEventListener('ended',nextSong,false);
    audioPlayer.addEventListener('error',errorFallback,true);
    document.getElementById("player").appendChild(audioPlayer);
    nextSong();
}
function nextSong() {
    if(urls[next]!=undefined) {
        var audioPlayer = document.getElementsByTagName('audio')[0];
        if(audioPlayer!=undefined) {
            audioPlayer.src=urls[next];
            audioPlayer.load();
            audioPlayer.play();
            next++;
        } else {
            loadPlayer();
        }
    } else {
        alert('the end!');
    }
}
function errorFallback() {
        nextSong();
}
function playPause() {
    var audioPlayer = document.getElementsByTagName('audio')[0];
    if(audioPlayer!=undefined) {
        if (audioPlayer.paused) {
            audioPlayer.play();
        } else {
            audioPlayer.pause();
        }
    } else {
        loadPlayer();
    }
}

    function stop() {
        var audioPlayer = document.getElementsByTagName('audio')[0];
        audioPlayer.pause();
        audioPlayer.currentTime = 0;
    }


function pickSong(num) {
    next = num;
    nextSong();
}

var urls = new Array();
    urls[0] = '01_horses_mouth/mp3/01. Let The Dog See The Rabbit preface.mp3';
    urls[1] = '01_horses_mouth/mp3/02. The Other Horse\'s Tale.mp3';
    urls[2] = '01_horses_mouth/mp3/03. Caged Tango.mp3';
    urls[3] = '01_horses_mouth/mp3/04. Crumbs.mp3';
    urls[4] = '01_horses_mouth/mp3/05. Mood Elevator Reprise.mp3';
    urls[5] = '01_horses_mouth/mp3/06. Mood Elevator.mp3';
    urls[6] = '02_dub_project/mp3/01. Fearless Dub.mp3';
    urls[7] = '02_dub_project/mp3/02. Original Sound Dub.mp3';
    urls[8] = '02_dub_project/mp3/03. Rhok Shok Dub.mp3';
    urls[9] = '02_dub_project/mp3/04. Tron Dub.mp3';
    urls[10] = '02_dub_project/mp3/05. Eastern Fire Dub.mp3';
    urls[11] = '02_dub_project/mp3/06. Mary Jane Dub.mp3';

var next = 0;
`

Can anyone see anything obvious that would make this not work on iPhone? 任何人都可以看到任何明显的东西会使这在iPhone上不起作用吗?

There's also code for a canvas element, but I've hidden that on the iPhone version - the canvas at any rate. 还有一个canvas元素的代码,但我已经将它隐藏在iPhone版本 - 无论如何都是画布上。 I commented out the code but that didn't seem to make a difference, so I'm guessing it's not a conflict. 我评论了代码,但这似乎没有什么区别,所以我猜这不是冲突。 Here's the site: 这是网站:

http://lisadearaujo.com/clientaccess/wot-sound/indexiPad.html http://lisadearaujo.com/clientaccess/wot-sound/indexiPad.html

On my browser versions, I have hidden the default audio player so I could use custom controls. 在我的浏览器版本中,我隐藏了默认音频播放器,因此我可以使用自定义控件。 This worked fine with the player in a hidden div. 这对于隐藏的div中的玩家来说效果很好。 On the iPhone, however, the div has to display in order to function, even with custom controls (or so it appears). 但是,在iPhone上,div必须显示才能运行,即使使用自定义控件(或出现)也是如此。

I hid the div with a low z-index rather than with display:none. 我用低z-index而不是display:none来隐藏div。

The HTML5 audio player on iPhone require the click of the user. iPhone上的HTML5音频播放器需要点击用户。

Work when you click on the player: 点击播放器时工作:

<audio src="foo.ogg" width="200px" height="200px" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM