简体   繁体   English

Raspberry Pi 3上的Java中的ProcessBuilder没有显示omxplayer的错误/输入流

[英]ProcessBuilder in Java on Raspberry Pi 3 not showing error/input stream for omxplayer

I am doing a little program in Java on a Raspberry pi 3 Jessie, and I am trying to use omxplayer to play a sound from inside the java program. 我在Raspberry pi 3 Jessie上用Java编写了一个小程序,我正在尝试使用omxplayer从java程序中播放声音。

I have the following code: 我有以下代码:

ProcessBuilder p = new ProcessBuilder("omxplayer", "/path/to/wav");
p.redirectErrorStream(true);

Process pr = p.start();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(pr.getInputStream()));
Executors.newSingleThreadExecutor().execute(new Runnable() {
    @Override
    public void run() {
        try {
            String line = "";
            while((line = bufferedReader.readLine()) != null) {
                System.out.println("Reading " + line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
});

The program will play the sound correctly, but will not output anything until it reaches the end of the wav and then prints all. 程序将正确播放声音,但在到达wav结束然后打印全部之前不会输出任何内容。 However, when I launch the same command directly in a terminal, I can see text showing during the wav. 但是,当我直接在终端中启动相同的命令时,我可以看到在wav期间显示的文本。

For example, when I press "+" or "-" in a terminal with omxplayer running, it changes the volume and prints "Current volume : blabla mB", but when I send through the ProcessBuilder "+" or "-", I can hear the sound of my wav changes, but still no outputs. 例如,当我在运行omxplayer的终端中按“+”或“ - ”时,它会更改音量并打印“当前音量:blabla mB”,但是当我通过ProcessBuilder发送“+”或“ - ”时,我可以听到我的wav变化的声音,但仍然没有输出。

It is weird because I have used ProcessBuilder for many other uses, and have never encountered a problem as such. 这很奇怪,因为我已经将ProcessBuilder用于许多其他用途,并且从未遇到过这样的问题。

Do you think the problem is with omxplayer's implementation? 你认为问题出在omxplayer的实现上吗? Or am I doing something wrong here? 或者我在这里做错了什么?

EDIT: 编辑:

I have tried reading the stream without the BufferedReader as such: 我试过在没有BufferedReader的情况下读取流:

InputStream inputStream = pr.getInputStream();
Executors.newSingleThreadExecutor().execute(new Runnable() {
    @Override
    public void run() {
        try {
            int read;
            while((read = inputStream.read()) >= 0) {
                System.out.println("Reading " + (char)read);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
});

in case the omxplayer did not send any line returns, but the problem remains. 如果omxplayer没有发送任何行返回,但问题仍然存在。

I had exactly the same problem and could fix it with the parameter -s (statistics). 我有完全相同的问题,可以使用参数-s (统计信息)修复它。 In this case, the player continuously puts status information and also all the start infos. 在这种情况下,玩家会持续放置状态信息以及所有开始信息。

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

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