有没有办法获得某种 nowplaying.txt 文件,其中包含 Rhythmbox 当前播放的文件?
我注意到这里和那里有几个用于此的插件,但它们都不起作用(它们似乎已经过时或根本不起作用,尽管尝试在这里和那里修复它们)。
答案1
我编写了一个小型 Java 应用程序来满足我的需求(它使用命令并将rhythmbox-client --print-playing
输出写入~/.rbplay
。每 3 秒调用一次命令并写入输出。以下代码在 CC-0 下可用。
import java.awt.*;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import javax.swing.*;
public class RBPlay
{
private JFrame frame;
private JLabel lblNewLabel;
private static RBPlay instance;
public static void main(String[] args) throws IOException, InterruptedException, InvocationTargetException
{
EventQueue.invokeAndWait(new Runnable()
{
public void run()
{
try
{
instance = new RBPlay();
instance.frame.setVisible(true);
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
File f = new File(System.getProperty("user.home"), ".rbplay");
f.createNewFile();
while(true)
{
Process p = Runtime.getRuntime().exec("rhythmbox-client --print-playing");
p.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while((line = br.readLine()) != null)
{
System.out.println(line);
FileWriter fw = new FileWriter(f);
fw.write(line);
fw.close();
instance.lblNewLabel.setText(line);
}
Thread.sleep(3000);
}
}
public RBPlay()
{
initialize();
}
private void initialize()
{
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout());
JLabel lblCurrentSong = new JLabel("Current song : ");
frame.getContentPane().add(lblCurrentSong, BorderLayout.WEST);
lblNewLabel = new JLabel("New label");
frame.getContentPane().add(lblNewLabel, BorderLayout.CENTER);
JLabel lblCloseThisWindow = new JLabel("Close this window to stop RBPlay");
frame.getContentPane().add(lblCloseThisWindow, BorderLayout.SOUTH);
frame.pack();
}
}
注意:此代码根本没有优化。这只是我写的一个简短的代码,但是,它确实有效!