简体   繁体   English

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

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

How can I get an MP3 audio file to play in iPhone Safari (OS 3.1)? 如何在iPhone Safari(OS 3.1)中播放MP3音频文件?

Currently, I am generating HTML eg 目前,我正在生成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. 这适用于OSX上的Safari,但不适用于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 Headers from Firefox. 在那里,文件的内容显示为文本,但是当使用Firefox的Live HTTP Headers检查时,它似乎不是mime类型的问题。

I have found approaches referenced here . 我找到了这里引用的方法。 These require the Safari Plugins setting to be on in the preferences, which is why it did not previously work for me. 这些需要在首选项中启用 Safari插件设置,这就是为什么以前没有为我工作的原因。

I imagine your best bet is to invoke a quicktime object in your web page. 我想你最好的办法是在你的网页中调用一个quicktime对象。 For playing mp3 files, your best bet is to serve a Winamp .pls style playlist with mimetype audio/x-scpls that serves as a signpost to the mp3 files. 对于播放mp3文件,最好的办法是提供一个Winamp .pls风格的播放列表,其中包含mimetype audio / x-scpls ,用作mp3文件的路标。 Create an embedded quicktime object around it. 围绕它创建一个嵌入式quicktime对象。 Try the docs for quicktime: 试试docs for quicktime:

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

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中它将可用(至少播放视频而不启动全屏播放器)

Use the HTML5 audio tag with an mp3 in it. 使用带有mp3的HTML5音频标签。 http://www.w3schools.com/tags/tag_audio.asp http://www.w3schools.com/tags/tag_audio.asp

Hey this simple html5 tag will do the trick 嘿,这个简单的html5标签将起到作用

<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. 它在iPhone上的作用是打开一个播放按钮,按下时会转到快速时间。 on the iPad, a scrubbing play control will come up with a play/pause button. 在iPad上,一个擦洗播放控件将出现一个播放/暂停按钮。 on both, the play control will size to the div they are in 在两者上,播放控件的大小与它们所处的div相同

As jottos points out, iPhone 3.x does not support HTML5 audio. 正如jottos所指出的,iPhone 3.x不支持HTML5音频。 If you want audio in the early versions of iPhone OS, you must use Quicktime specific code. 如果您想在早期版本的iPhone OS中使用音频,则必须使用Quicktime特定代码。 This example actually embeds an entire playlist (not just a single song). 这个例子实际上嵌入了一个完整的播放列表(不只是一首歌)。 If you want a single song, drop the qtnext parameters: 如果您想要一首歌曲,请删除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>"
>

I had issues with mp3 on my local development system (Linux/apache2). 我在本地开发系统(Linux / apache2)上遇到过mp3问题。 I was only apple to play .OGG files in both Firefox(8) and Chrome(15) from the local file system. 我只是苹果在本地文件系统中播放Firefox(8)和Chrome(15)中的.OGG文件。 If I used the audio tag to link to a remote .MP3 or .OGG file either would work though? 如果我使用音频标签链接到远程.MP3或.OGG文件可能会工作吗? 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. 我不确定为什么会这样,因为我的大部分本地音乐文件都是MP3,我花了一段时间才弄清楚它是文件格式的问题。

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

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