如何播放 html 中的 midi 文件

发布于 2024-11-01 23:47:20 字数 273 浏览 1 评论 0 原文

我怎样才能在我的 html/php 页面中播放 midi 文件

现在我上网并得到了很多简单的嵌入代码,如下所示,

<EMBED SRC="C:\Windows\Media\Onestop.mid" hidden=true autostart=true loop=1>

但我的 firefox 说要安装插件 - Quicktime 播放器

我不认为这是方法或如何绕过上述问题,可能是您是否可以建议另一种方法来执行此操作(如果有)。

how can I play a midi file in my html/php page

Right now I surf the net and got lots of simple embed code like the one I given below

<EMBED SRC="C:\Windows\Media\Onestop.mid" hidden=true autostart=true loop=1>

But my firefox says to install plugin - Quicktime player

I don't think this is the way or how to bypass this above said issue, may be if you can suggest another method to do this if any.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

空宴 2024-11-08 23:47:20

我知道已经有一段时间了,但这是 Google 的“网站 midi 播放器”的顶部,所以我想我应该提出一个解决方案。

我制作了一个网站,想要播放 midi 文件,您可以使用一个 Javascript 插件: http://www.midijs .net/

只需包含库即可:

然后是要播放的文件:< script>MIDIjs.play('path/to.your/file.mid');

重要编辑
看起来远程文件正在进行加密挖掘,这不太理想。您应该将文件存储在本地并删除 t("https://coinhive.com/lib/coinhive.min.js",D),或者使用 GitHub 中的原始代码:https://github.com/babelsberg/babelsberg-js/tree/master/midijs

感谢@David de Kleer 指出了这一点。

I know it's been a while, but this is top of Google for "website midi player", so I thought I'd drop in a solution.

I made a website and wanted to play a midi file, and there's a Javascript plugin you can use: http://www.midijs.net/

Just include the library:
<script src='http://www.midijs.net/lib/midi.js'></script>

And then the file you want to play: <script>MIDIjs.play('path/to.your/file.mid');</script>

Important edit
It seems that the remote file is doing Crypto mining, which is less than ideal. You should either store the file locally and remove t("https://coinhive.com/lib/coinhive.min.js",D), or use the original code from GitHub: https://github.com/babelsberg/babelsberg-js/tree/master/midijs

Thanks to @David de Kleer for pointing that out.

酒绊 2024-11-08 23:47:20

使用 html-midi-player,可以在网站中嵌入 MIDI 文件只需插入一个 midi-player 元素(一个自定义 HTML 元素,其工作方式与 audio 元素非常相似,但适用于 MIDI 文件):

<midi-player src="jazz.mid" sound-font></midi-player>

完整演示:

<midi-player src="https://cdn.jsdelivr.net/gh/cifkao/html-midi-player@2b12128/jazz.mid" sound-font>
</midi-player>

<!-- The following needs to be inserted somewhere on the page for the player(s) to work. -->
<script src="https://cdn.jsdelivr.net/combine/npm/[email protected],npm/@magenta/[email protected]/es6/core.js,npm/focus-visible@5,npm/[email protected]"></script>

全面披露:我是 html-midi-player 的作者。

播放功能由 Google 的 Magenta.js 库。也可以直接使用 Magenta.js 来播放 MIDI 文件,但这需要大量的 JavaScript 编码,这就是我创建 html-midi-player 的原因。

With html-midi-player, it is possible to embed a MIDI file in a website simply by inserting a midi-player element (a custom HTML element which works a lot like the audio element, but for MIDI files):

<midi-player src="jazz.mid" sound-font></midi-player>

Complete demo:

<midi-player src="https://cdn.jsdelivr.net/gh/cifkao/html-midi-player@2b12128/jazz.mid" sound-font>
</midi-player>

<!-- The following needs to be inserted somewhere on the page for the player(s) to work. -->
<script src="https://cdn.jsdelivr.net/combine/npm/[email protected],npm/@magenta/[email protected]/es6/core.js,npm/focus-visible@5,npm/[email protected]"></script>

Full disclosure: I'm the author of html-midi-player.

The playback functionality is provided by Google's Magenta.js library. It's also possible to use Magenta.js directly to play MIDI files, but this requires a non-trivial amount of JavaScript coding, which is why I created html-midi-player.

我最亲爱的 2024-11-08 23:47:20

使用适用于现代浏览器的 Web Audio API。请参阅完整的播放器示例。它适用于桌面和移动设备。

Use Web Audio API for modern browsers. See complete example of player. It works on desktop and mobile.

土豪我们做朋友吧 2024-11-08 23:47:20

据我所知,没有跨浏览器的方法可以做到这一点:Flash,在网页上嵌入音频时最常见的选项,不播放 Midi 文件

唯一的方法确实是 embed 方法,其是否有效将取决于用户浏览器的设置方式。必须安装可以处理该文件的插件(如 Quicktime)。如果计算机上出现“安装插件”对话框,则该对话框将无法运行。

我认为唯一明智的方法是将这些 Midis 转换为 MP3 文件。

As far as I know, there is no cross-browser way to do this: Flash, the most common option when embedding audio on a web page, doesn't play Midi files.

The only way is indeed the embed method, and whether that works will depend on how the user's browser is set up. A plug-in (like Quicktime) will have to be installed that can handle the file. If the "install plugin" dialog appears on a computer, it won't work there.

I think the only sane way is to convert those Midis to MP3 files.

你是年少的欢喜 2024-11-08 23:47:20

Java 可以播放 MIDI 文件,并且大多数 PC 上都安装了必要的插件(在工厂中)

不完整的示例 此处此处

Java can play MIDI files, and the necessary plugin is installed (in the factory) on most PCs

Incomplete examples here and here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文