我开发了我的第一个 Laravel Web 应用程序,您可以在以下网址找到它:www.sharpguitartraining.com,它使用来自gleitz/midi-js-soundfonts CDN 的 .mp3 文件一次弹奏一个吉他音符,并且运行良好在台式电脑上,但在 iOS 和 Android 设备上完全静音。
这是我在网站上播放声音的方式:
<script src="https://cdn.rawgit.com/mudcube/MIDI.js/a8a84257/inc/shim/Base64.js"></script>
<script src="https://cdn.rawgit.com/mudcube/MIDI.js/a8a84257/inc/shim/Base64binary.js"></script>
<script src="https://cdn.rawgit.com/mudcube/MIDI.js/a8a84257/inc/shim/WebAudioAPI.js"></script>
<!-- midi.js package -->
<script src="https://cdn.rawgit.com/mudcube/MIDI.js/a8a84257/js/midi/audioDetect.js"></script>
<script src="https://cdn.rawgit.com/mudcube/MIDI.js/a8a84257/js/midi/gm.js"></script>
<script src="https://cdn.rawgit.com/mudcube/MIDI.js/a8a84257/js/midi/loader.js"></script>
<script src="https://cdn.rawgit.com/mudcube/MIDI.js/a8a84257/js/midi/plugin.audiotag.js"></script>
<script src="https://cdn.rawgit.com/mudcube/MIDI.js/a8a84257/js/midi/plugin.webaudio.js"></script>
<script src="https://cdn.rawgit.com/mudcube/MIDI.js/a8a84257/js/midi/plugin.webmidi.js"></script>
<!-- utils -->
<script src="https://cdn.rawgit.com/mudcube/MIDI.js/a8a84257/js/util/dom_request_xhr.js"></script>
<script src="https://cdn.rawgit.com/mudcube/MIDI.js/a8a84257/js/util/dom_request_script.js"></script>
function playNote_CDN(note, sonido_id, velocity, delay, mensaje) {
var instrument_name = sonido_id ? $('#sonidos')[0].options[sonido_id].text : $('#sonidos')[0].selectedOptions[0].text;
var delay = delay ? delay : 0; // play one note every quarter second
var velocity = velocity ? velocity : 127; // how hard the note hits
var note = note ? note - 1 : 61;
var volumen = $('#volumen').val() / 100 * 127;
MIDI.loadPlugin({
soundfontUrl: "http://gleitz.github.io/midi-js-soundfonts/FluidR3_GM/",
instrument: instrument_name,
onprogress: function(state, progress) {
},
onsuccess: function () {
if (mensaje) {
muestraMensaje("Instrumento " + instrument_name + " cargado.", 3);
}
MIDI.programChange(0, MIDI.GM.byName[instrument_name].number);
MIDI.setVolume(0, volumen);
MIDI.noteOn(0, note, velocity, delay);
MIDI.noteOff(0, note, delay + 1);
}
});
}
我不知道如何继续,所以非常感谢任何帮助。
谢谢!