简体   繁体   English

在任何网络浏览器上通过点击图片来实现MIDI控制(Chrome无法正常运行)

[英]Implementing MIDI control by clicking on image, on any web browser (chrome doesn't work)

I have been hit with some problems on my html coding that is, at first glance,simple, but I can't manage to solve it. 乍看之下,我的html编码遇到了一些问题,但很简单,但我无法解决。 Any help is welcome. 欢迎任何帮助。 Very important: I want this code working by only using HTML and Javascript But CSS is allowed too. 非常重要: 我希望此代码仅通过使用HTML和Javascript运行,但CSS也允许。

I am trying to make where a MIDI music (it has to be MIDI) would play when you click on a image ( I don't want it to start when you open the page, but to start only when you click on the image) and stop when you click on an other one. 我试图使MIDI音乐(必须是MIDI)在您单击图像时播放的位置( 我不希望它在打开页面时启动,而仅在单击图像时启动)并在单击另一个时停止。 I have managed to make a code that work on Firefox and Opera, but it won't work on MS IE nor Chrome: 我设法制作了可以在Firefox和Opera上运行的代码,但是在MS IE或Chrome上无法运行:

<html>
<head>



<script LANGUAGE="JavaScript">


function switchOn(){

  document.all.changetrack.data = "knight.mid";

}

function switchOff(){

  document.all.changetrack.data ="none.mid";

}

//-->

</SCRIPT>

</head>
<body>
<a onclick="switchOn()"><img src="play.gif" border="0"/></a><a onclick="switchOff()"><img src="stop.gif" border="0"/></a>
<br>
<OBJECT name="changetrack" type="audio/x-midi" data="none.mid">
  <PARAM name="autostart" value="true">
  <PARAM name="loop" value="true">
  <PARAM name= "hidden" value="true">
</OBJECT>
<br>
<object data="knight.mid">
  <param name="autostart" value="false">
  <PARAM name= "hidden" value="true">
If you're seeing this, you don't have a MIDI player
on your computer.
</object>
</body>
</html>

I am not sure, but it seems that while the change of file is actually done, the autostart don't activate the music on IE and Chrome. 我不确定,但似乎文件更改实际上已完成,但自动启动不会激活IE和Chrome上的音乐。

I have also manage to create an "hybrid" version that work on MS IE, by "cheating" a bit and using the tag: 我还设法通过“作弊”一点并使用标签来创建在MS IE上工作的“混合”版本:

<html>
<head>

<BGSOUND SRC="none.mid" ID="changemusic" loop="infinite">

<script LANGUAGE="JavaScript">

<!--



function switchOn(){

  document.all.changemusic.src = "knight.mid"
  document.all.changetrack.data = "knight.mid"

}

function switchOff(){

  document.all.changemusic.src ="none.mid"
  document.all.changetrack.data ="none.mid"

}

//-->

</SCRIPT>

</head>
<body>
<a onclick="switchOn()"><img src="play.gif" border="0"/></a><a onclick="switchOff()"><img src="stop.gif" border="0"/></a>
<br>
<OBJECT name="changetrack" type="audio/x-midi" data="none.mid">
  <PARAM name="autostart" value="true">
  <PARAM name="loop" value="true">
  <PARAM name= "hidden" value="true">
</OBJECT>
<br>
<object data="knight.mid">
  <param name="autostart" value="false">
  <PARAM name= "hidden" value="true">
If you're seeing this, you don't have a MIDI player
on your computer.
</object>
</body>
</html>

But it still (of course) won't work on Chrome. 但它仍然(当然)在Chrome上无法正常工作。 Any solution to make it work on Chrome? 有什么解决方案可以在Chrome上运行吗?

I really would like a single code able to work on all Browsers. 我真的想要一个能够在所有浏览器上运行的代码。

Thanks in advance. 提前致谢。

(also, I have already tried to do it with the the tag, it only work with Firefox) (此外,我已经尝试使用标记来完成此操作,它仅适用于Firefox)

I've seen a solution for this problem only for IE till now: 到目前为止,我仅针对IE看到过针对此问题的解决方案:

<embed src="music.mid" hidden="true" type="audio/midi" autostart="0" loop="1" name="myMidiMusic"/>
<img src="play.png" onclick="document.myMidiMusic.play()"/>
<img src="stop.png" onclick="document.myMidiMusic.stop()"/>

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

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