简体   繁体   English

容器化 JAR (Java) 如何访问默认的系统混音器?

[英]How can a containerized JAR (Java) access the default system mixer?

I previously took this question down, it's going back up since it's still a problem we're encountering.我之前把这个问题记下来了,它又回来了,因为它仍然是我们遇到的问题。 We have a JAR that we're resurrecting from three years ago.我们有一个从三年前复活的 JAR。 Back then (before I joined the project), it ran bare-metal (presumably on an RPM-based Linux distribution).那时(在我加入该项目之前),它运行裸机(大概在基于 RPM 的 Linux 发行版上)。 Before a developer left, he had containerized it (CentOS7) and left us with very little documentation.在一位开发人员离开之前,他已经将它容器化(CentOS7)并且给我们留下了很少的文档。

Ultimately, the JAR is calling the function getSourceDataLine() described here: https://docs.oracle.com/javase/7/docs/api/javax/sound/sampled/AudioSystem.html#getSourceDataLine(javax.sound.sampled.AudioFormat)最终,JAR 正在调用此处描述的函数 getSourceDataLine(): https://docs.oracle.com/javase/7/docs/api/javax/sound/sampled/AudioSystem.html#getSourceDataLine(javax.sound.sampled。音频格式)

The returned line will be provided by the default system mixer, or, if not possible, by any other mixer installed in the system that supports a matching SourceDataLine object.返回的行将由默认系统混音器提供,或者,如果不可能,由系统中安装的任何其他支持匹配 SourceDataLine 对象的混音器提供。

However, the program encounters an IllegalArgumentException但是,程序遇到了 IllegalArgumentException

if the system does not support at least one source data line supporting the specified audio format through any installed mixer如果系统不支持至少一条通过任何已安装的混音器支持指定音频格式的源数据线

java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 8000.0 Hz, 16 bit, stereo, 4 bytes/frame, big-endian is supported.  
at javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:479)  
at javax.sound.sampled.AudioSystem.getSourceDataLine(AudioSystem.java:606)  

I inspected the contents of the sound.properties file: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre/lib/sound.properties inside the container and ./jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/lib/sound.properties on the host.我检查了 sound.properties 文件的内容: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre/lib/sound.properties./jvm/java-1.8.0-openjdk-1.8.0.322.b06-2.el8_5.x86_64/jre/lib/sound.properties在主机上。 Both are completely commented/empty, so I assume the default system mixer is being used.两者都是完全注释/空的,所以我假设正在使用默认的系统混音器。

In the docker/docker-compose run parameters, I tried adding all capabilities to the Linux container, and that did not resolve the issue (regardless of permissions, I assume the needed sound card device doesn't appear at all).在 docker/docker-compose 运行参数中,我尝试将所有功能添加到 Linux 容器,但这并没有解决问题(无论权限如何,我都认为所需的声卡设备根本没有出现)。

I suspected there was a --device flag that could be passed to the docker run command (or docker-compose yaml).我怀疑有一个--device标志可以传递给docker run命令(或 docker-compose yaml)。 However, I tried running the container as privileged (access to all host devices), and this did not allow access to a system mixer.但是,我尝试以特权身份运行容器(访问所有主机设备),但这不允许访问系统混音器。

I may try inspecting the devices available to the Java runtime with code similar to here: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4269230我可以尝试使用类似于此处的代码检查 Java 运行时可用的设备: https ://bugs.java.com/bugdatabase/view_bug.do?bug_id=4269230

I have heard "audio is difficult in containers".我听说“容器中的音频很困难”。 I may try doing full virtualization with QEMU to to try to recreate the host environment, but that seems a little drastic.我可能会尝试使用 QEMU 进行完全虚拟化以尝试重新创建主机环境,但这似乎有点激烈。 If anyone has worked with the Java audio system as well as containers and could point me in the right direction, that would be much appreciated.如果有人使用过 Java 音频系统和容器并且可以为我指明正确的方向,那将不胜感激。

In Linux accessing the audio devices is all done via the filesystem.在 Linux 中,访问音频设备都是通过文件系统完成的。 So if you mount the necessary files (/dev/audio?) into the container and give suitable privileges you should be good to go.因此,如果您将必要的文件(/dev/audio?)安装到容器中并提供适当的权限,那么您应该很高兴。

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

相关问题 有没有办法在.jar文件中设置Java系统属性,以便它们具有默认值但可以在命令行覆盖? - Is there any way to set Java system properties in a .jar file so that they have default values but can be overridden at the command line? 使用Java AudioSystem API,系统上安装的混音器在Safari和Firefox上有所不同 - Mixer installed on system are different on Safari and Firefox using java AudioSystem APIs Java jar无法访问资源 - Java jar can't access resources Java JAR文件是否可能损坏您的系统?如何检查它正在做什么? - Is it possible for a Java JAR file to damage your system and how can you check what it's doing? JAVA:将文件包含在jar中以及如何访问它们 - JAVA: including files in jar and how to access them 如何从Java Jar访问外部文件 - How to access outside file from java jar Java-如何访问打包在applet jar中的图像 - Java - How to access an image packed in an applet jar 如何强制使用jar(或运行jar的jvm)utf-8而不是系统的默认编码 - How to force a jar to use(or the jvm that jar runs in) utf-8 instead of the system's default encoding 如何访问jar中的资源,它可以存在于多个jar中 - How to access resources in jar where it can be present in multiple jar Java Applet可以访问本地文件系统吗 - Can a Java Applet Access Local File System
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM