简体   繁体   English

在heroku上部署的Web应用程序中使用Java Sound API

[英]Using the Java Sound API in a web-app deployed on heroku

We are working on a project for creating music based on crowd sourcing. 我们正在开展一个基于众包创作音乐的项目。 People vote for every note until the vote is closed, and then move on to the next vote until the canvas for the music is filled. 人们会为每个音符投票,直到投票结束为止,然后继续进行下一个投票,直到为音乐填充画布。 A similar project is crowdsound, if you want to get an idea of what it looks like. 如果您想了解它的外观,也可以进行类似的项目。

We've hosted the .war on heroku and we've managed to make everything work, except the sound. 我们将.war托管在heroku上,并且设法使所有功能(声音除外)都能正常工作。 Every time we try to call the Java Sound API (we use the midi synthesizer), we get the following error: 每次我们尝试调用Java Sound API(我们使用midi合成器)时,都会出现以下错误:

2017-03-10T09:49:01.338821+00:00 app[web.1]: javax.sound.midi.MidiUnavailableException: Can not open line
2017-03-10T09:49:01.339228+00:00 app[web.1]:    at com.sun.media.sound.SoftSynthesizer.open(SoftSynthesizer.java:1155)
2017-03-10T09:49:01.339288+00:00 app[web.1]:    at com.sun.media.sound.SoftSynthesizer.open(SoftSynthesizer.java:1066)
2017-03-10T09:49:01.339340+00:00 app[web.1]:    at music.MusicPlayer.run(MusicPlayer.java:99)
2017-03-10T09:49:01.339391+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:745)
2017-03-10T09:49:01.340759+00:00 app[web.1]: Caused by: java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian is supported.
2017-03-10T09:49:01.340869+00:00 app[web.1]:    at javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:479)
2017-03-10T09:49:01.340924+00:00 app[web.1]:    at javax.sound.sampled.AudioSystem.getSourceDataLine(AudioSystem.java:606)
2017-03-10T09:49:01.340975+00:00 app[web.1]:    at com.sun.media.sound.SoftSynthesizer.open(SoftSynthesizer.java:1095)
2017-03-10T09:49:01.341045+00:00 app[web.1]:    ... 3 more

Does this mean that we cannot use the midi synthesizer in a web app, or is there some way to make this work? 这是否意味着我们不能在Web应用程序中使用Midi合成器,还是有某种方法可以使这项工作正常进行?

You simply cannot play a sound from a Java WAR, because it's executed on the server side. 您根本无法播放Java WAR发出的声音,因为它是在服务器端执行的。 Additionally, the heroku instance may be lacking the sound hardware altogether. 此外,heroku实例可能完全缺少声音硬件。

If you'd like to generate sound that is then served to the web client, you need to either use some MIDI renderer that produces a sound file, and then serve the resulting audio file to the client (eg as WAV file) or simply serve MIDI to the client and have the browser play the MIDI via a library like eg MIDI.js . 如果您想生成然后提供给Web客户端的声音,则需要使用一些MIDI渲染器来生成声音文件,然后将生成的音频文件提供给客户端(例如,作为WAV文件),或者只提供MIDI到客户端,并让浏览器通过MIDI.js之类的库播放MIDI。

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

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