Html 关于在网页上嵌入 MIDI 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7677366/
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 10:59:03  来源:igfitidea点击:

About embed midi files on a webpage

htmliosmidi

提问by rooofl

I am working on a project related to vintage web designs. I would like to embed and autoplay a midi file but:

我正在做一个与复古网页设计相关的项目。我想嵌入和自动播放一个 MIDI 文件,但是:

  1. It doesen't work on IOS (I tried with my ipad)
  2. On Firefox, sometimes the tune is not played, I don't know why.
  1. 它在 IOS 上不起作用(我用 ipad 试过)
  2. 在 Firefox 上,有时无法播放曲调,我不知道为什么。

Does the midi player depends on the browser or a plugin? Can I find a univeral alternative to play my tune?

midi播放器是依赖浏览器还是插件?我可以找到一种通用的替代方法来播放我的曲调吗?

I am using the <embed>tag this way:

我以<embed>这种方式使用标签:

<embed src="tune.mid" hidden="true" autostart="true" autoplay="true">

回答by Brian Ellis

I've referenced this question before and fell upon the answer of using the library midijs. However, since that lib now has a bitcoin miner included, I've made a variant without the mining code:

我之前已经引用过这个问题,并想到了使用库midijs的答案。但是,由于该库现在包含一个比特币矿工,因此我制作了一个没有挖掘代码的变体:

https://kitchwww.github.io/midi/midi.js

https://kitchwww.github.io/midi/midi.js

It can be included and used in exactly the same way:

它可以以完全相同的方式包含和使用:

<script type='text/javascript' src='https://kitchwww.github.io/midi/midi.js'></script>
<a href="#" onClick="function(){
MIDIjs.initAll();
MIDIjs.play('path/to/yoursong.midi');}">Play My Song</a>

EDIT: updated to include an init function to be called on a User Gesture, as all audio must now be initiated from one.

编辑:更新为包含要在用户手势上调用的 init 函数,因为现在所有音频都必须从一个开始。

回答by Design by Adrian

Yes, the embedtag is reserved for plugins, which Mobile Safari doesn't support.

是的,嵌入标签是为插件保留的,Mobile Safari 不支持。

Take a look at HTML5 audiotag, which is supported by most browsers.

看看大多数浏览器都支持的HTML5 音频标签。

But please don't play music on a webpage... it's annoying - most either listens to music, have the speakers turned off, or are at the office.

但是请不要在网页上播放音乐...这很烦人 - 大多数人要么听音乐,要么关闭扬声器,要么在办公室。

回答by Anirath

Use the HTML5 Audio tag. But like The guy before me said.... please reconsider music on your page.

使用 HTML5 音频标签。但就像我之前的那个人说的……请重新考虑您页面上的音乐。

<audio src="example.midi" preload="auto" autoplay="autoplay"></audio>

回答by user236939

Your HTML is OK. The problem is that some lower class browsers have lost the ability to play midi files. They have to install an add on. Real Player used to be a good solution, but now they are pushing a cloud subscription. There are plenty of other midi players around, but the users have to install one.

你的 HTML 没问题。问题是一些低级浏览器已经失去了播放 MIDI 文件的能力。他们必须安装一个附加组件。Real Player 曾经是一个很好的解决方案,但现在他们正在推动云订阅。周围还有很多其他的 MIDI 播放器,但用户必须安装一个。

回答by jofeu

Browsers dropped support for playing MIDI files natively over time. You might want to try MIDI.js, a JavaScript based cross browser library.

随着时间的推移,浏览器不再支持本地播放 MIDI 文件。您可能想尝试 MIDI.js,这是一个基于 JavaScript 的跨浏览器库。

Add the MIDI.js script to your webpage:

将 MIDI.js 脚本添加到您的网页:

    <script type='text/javascript' src='http://www.midijs.net/lib/midi.js'></script>

And then add a link to start playing:

然后添加一个链接开始播放:

    <a href="#" onClick="MIDIjs.play('path/to/yoursong.midi');">Play My Song</a>

Take a look at http://www.midijs.netfor details.

有关详细信息,请查看http://www.midijs.net

回答by Rob

For mid, and kar files, I suggest using vanBasco midi player as your default player. See the source on http://midkar.com/blues/blues_01.html

对于 mid 和 kar 文件,我建议使用 vanBasco midi 播放器作为您的默认播放器。请参阅http://midkar.com/blues/blues_01.html上的来源

To Embed; embed src="musicfile.mid" width=144 height=60 autostart=true repeat=false loop=false (replace the "musicfile.mid" with the name of your midi file)

镶嵌; embed src="musicfile.mid" width=144 height=60 autostart=true repeat=false loop=false (用你的midi文件名替换"musicfile.mid")

回答by artgal

Well, here it is Aug 13, 2017 and don't you know embedding a bg midi on a web page is still a mystery.

好吧,现在是 2017 年 8 月 13 日,您不知道在网页上嵌入 bg MIDI 仍然是个谜。

In fact I'm pretty certain it can't even be done anymore (except IE's bgsound src, which still works fine for me).

事实上,我很确定它甚至不能再做(除了 IE 的 bgsound src,它对我来说仍然很好用)。

But as for Firefox and Chrome, the solution provided by jofeu is a great work-around.

但是对于 Firefox 和 Chrome,jofeu 提供的解决方案是一个很好的解决方法。

I only wish there was a way to embed so the midi just starts playing on page load, without having to click anything. I guess those days are gone.

我只希望有一种嵌入方式,这样 MIDI 就可以在页面加载时开始播放,而无需单击任何内容。我想那些日子已经一去不复返了。