简体   繁体   English

在iPhone上循环播放HTML5音频

[英]Looping HTML5 audio on the iPhone

I'm trying to make a HTML5 webapp that simply plays a sound over and over and over again, on my iPhone. 我正在尝试制作一个HTML5 webapp,它只是在我的iPhone上一遍又一遍地播放声音。 I don't know any Obj-C to do it natively. 我不知道任何Obj-C本地做它。

What I have works fine, but the sound only plays once: 我的工作正常,但声音只播放一次:

<!DOCTYPE html>
<html>
    <head>
        <title>noisemaker!</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="maximum-scale=1, minimum-scale=1, width=device-width, user-scalable=no" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
    </head>
    <body>
        <audio src="noise.mp3" autoplay controls loop></audio>
    </body>
</html>

Is there a way to either bypass the QuickTime audio screen and loop it in the webpage, or get the QuickTime audio screen to loop the sound? 有没有办法绕过QuickTime音频屏幕并在网页中循环播放,或者让QuickTime音频屏幕循环播放声音?

I found that the "loop" attribute does not seem to fully work in the latest implementation of the HTML5 audio element on the iPhone (iOS 4.0). 我发现“loop”属性似乎并不完全适用于iPhone(iOS 4.0)上HTML5音频元素的最新实现。 I found this to be a workaround: 我发现这是一个解决方法:

<audio src="noise.mp3" onended="this.play();" controls="controls" autobuffer></audio>

I found that you have to not put "loop" in the above, or the "onended" event seems not to trigger (ie "loop" is partially implemented). 我发现你必须不在上面放“循环”,否则“onended”事件似乎不会触发(即“循环”部分实现)。

Note that "autoplay" is intentionally disabled on the iPhone. 请注意,iPhone上有意禁用“自动播放”。

It also seems that the "volume" attribute is not fully implemented at this time as well. 此时似乎“音量”属性也未完全实现。

Note that with iOS 4 audio is played without the full-screen QT player. 请注意,iOS 4音频播放时没有全屏QT播放器。

Have you tried using key/value pairs for the attributes. 您是否尝试过为属性使用键/值对。 I know you SHOULD be able to just specify the attr, but just to play devil's advocate. 我知道你应该只能指定attr,但只是为了扮演魔鬼的拥护者。 Try: 尝试:

<audio src="noise.mp3" autoplay="autoplay" controls="controls" loop="loop"></audio>

关于什么:

<audio src="noise.mp3" autoplay="" controls="" onended="this.play()"></audio>

iPhone OS 3.0不完全支持<audio>标签 - 所有它将用它完成QuickTime风格的全部播放。

您可以使用老式的嵌入标记来完成,但我不知道Mobile Safari是否会遵循其循环属性。

Playing media like video or sounds are not allowed (so far). 不允许播放视频或声音等媒体(目前为止)。 If you want to play video or audio, the iPhone will open it in an external (default) player. 如果您想播放视频或音频,iPhone将在外部(默认)播放器中打开它。 When the player is open, you do not have any control over the webpage untill the user shut-down the external player or the video/sound has stopped by itself. 当播放器打开时,您无法控制网页,直到用户关闭外部播放器或视频/声音自行停止。

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

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