Html 如何让 mp3 文件在 iPhone Safari 网络浏览器中播放?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2240710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:10:32  来源:igfitidea点击:

How to get mp3 files to play in iPhone Safari web browser?

iphonehtmlmacossafarimp3

提问by grrussel

How can I get an MP3 audio file to play in iPhone Safari (OS 3.1)?

如何让 MP3 音频文件在 iPhone Safari (OS 3.1) 中播放?

Currently, I am generating HTML e.g.

目前,我正在生成 HTML 例如

<a href="file.mp3"><img src="sound.png" alt="Play audio"/></a>

to play the file on clicking on the nested image. This works on Safari on OSX, but not on the iPhone. There, the content of the file is shown as text, but it does not appear to be a mime-type problem when checked with Live HTTP Headersfrom Firefox.

单击嵌套图像即可播放文件。这适用于 OSX 上的 Safari,但不适用于 iPhone。在那里,文件的内容显示为文本,但当使用来自 Firefox 的Live HTTP Headers检查时,它似乎不是 mime 类型的问题。

I have found approaches referenced here. These require the Safari Plugins setting to be onin the preferences, which is why it did not previously work for me.

我找到了这里引用的方法。这些需要在首选项中启用Safari 插件设置,这就是为什么它以前对我不起作用的原因。

回答by spender

I imagine your best bet is to invoke a quicktime object in your web page. For playing mp3 files, your best bet is to serve a Winamp .pls style playlist with mimetype audio/x-scplsthat serves as a signpost to the mp3 files. Create an embedded quicktime object around it. Try the docs for quicktime:

我想你最好的办法是在你的网页中调用一个 quicktime 对象。要播放 mp3 文件,最好的办法是提供带有 mimetype audio/x-scplsWinamp .pls 样式播放列表,作为 mp3 文件的路标。在它周围创建一个嵌入的 quicktime 对象。试试quicktime的文档:

http://www.apple.com/quicktime/tutorials/embed.html

http://www.apple.com/quicktime/tutorials/embed.html

回答by Samuel

If you manage to get it working, it will play in the QuickTime Application (Full screen).

如果您设法让它工作,它将在 QuickTime 应用程序(全屏)中播放。

The HTML5 sound API is not available in the current iPhone OS (3.XX), but in OS 4.XX it will be available (at least playing video without launching the full screen player)

HTML5 声音 API 在当前的 iPhone OS (3.XX) 中不可用,但在 OS 4.XX 中它将可用(至少在不启动全屏播放器的情况下播放视频)

回答by kingjeffrey

Use the HTML5 audio tag with an mp3 in it. http://www.w3schools.com/tags/tag_audio.asp

使用带有 mp3 的 HTML5 音频标签。http://www.w3schools.com/tags/tag_audio.asp

回答by jottos

Hey this simple html5 tag will do the trick

嘿,这个简单的 html5 标签可以解决问题

<audio src="someUrlToContent" controls="controls"> </audio>

<audio src="someUrlToContent" controls="controls"> </audio>

what this does on the iPhone is bring up a play button that when pushed will go to quicktime. on the iPad, a scrubbing play control will come up with a play/pause button. on both, the play control will size to the div they are in

这在 iPhone 上的作用是调出一个播放按钮,按下该按钮时将转到 quicktime。在 iPad 上,滚动播放控件会带有播放/暂停按钮。在这两种情况下,播放控件的大小都会调整到它们所在的 div

回答by kingjeffrey

As jottos points out, iPhone 3.x does not support HTML5 audio. If you want audio in the early versions of iPhone OS, you must use Quicktime specific code. This example actually embeds an entire playlist (not just a single song). If you want a single song, drop the qtnext parameters:

正如 jottos 指出的那样,iPhone 3.x 不支持 HTML5 音频。如果您想在 iPhone OS 的早期版本中使用音频,则必须使用 Quicktime 特定代码。这个例子实际上嵌入了整个播放列表(不仅仅是一首歌曲)。如果您想要一首歌曲,请删除 qtnext 参数:

<embed
    src="riding-with-the-king.jpg"
    href="songs/01-riding-with-the-king.mp3"
    artworkdata="riding-with-the-king.jpg"
    type="audio/x-mp3"
    target="myself"
    scale="1"
    controller="false"
    loop="false"
    autoplay="false"
    allowembedtagoverrides="true"
    height="500"
    width="500"
    qtnext1="<songs/02 Ten Long Years.mp3> T<myself> E<controller=true autoplay=true loop=false>" 
    qtnext2="<songs/03 Key to the Highway.mp3> T<myself>" 
    qtnext3="<songs/04 Marry You.mp3> T<myself>" 
    qtnext4="<songs/05 Three O'Clock Blues.mp3> T<myself>"
    qtnext5="<songs/06 Help the Poor.mp3> T<myself>"
    qtnext6="<songs/07 I Wanna Be.mp3> T<myself>"
    qtnext7="<songs/08 Worried Life Blues.mp3> T<myself>"
    qtnext8="<songs/09 Days of Old.mp3> T<myself>"
    qtnext9="<songs/10 When My Heart Beats Like a Hammer.mp3> T<myself>"
    qtnext10="<songs/11 Hold on I'm Coming.mp3> T<myself>"
    qtnext11="<songs/12 Come Rain or Come Shine.mp3> T<myself>"
>

回答by esse

I had issues with mp3 on my local development system (Linux/apache2). I was only apple to play .OGG files in both Firefox(8) and Chrome(15) from the local file system. If I used the audio tag to link to a remote .MP3 or .OGG file either would work though? I am not sure why this is the case and since most of my local music files are MP3 it took me awhile to figure out that it was the file format that was the problem.

我在本地开发系统 (Linux/apache2) 上遇到了 mp3 问题。我只是在 Firefox(8) 和 Chrome(15) 中从本地文件系统播放 .OGG 文件的苹果。如果我使用音频标签链接到远程 .MP3 或 .OGG 文件,那么两者都可以工作吗?我不知道为什么会这样,因为我的大多数本地音乐文件都是 MP3,所以我花了一段时间才弄清楚这是文件格式的问题。