Como enviar o arquivo atualmente sendo reproduzido para um arquivo de texto no Rhythmbox?

1

Existe uma maneira de ter um arquivo nowplaying.txt de algum tipo que contenha o arquivo atual do Rhythmbox?

Eu notei alguns plugins aqui e ali para isso, mas nenhum deles funciona (eles parecem estar desatualizados ou simplesmente não funcionam, apesar de tentar consertá-los aqui e ali).

    
por utybo 04.08.2016 / 15:40

1 resposta

0

Codifiquei um pequeno aplicativo Java que cobre minhas necessidades (ele usa o comando rhythmbox-client --print-playing e grava a saída em ~/.rbplay . O comando é chamado e a saída é gravada a cada 3 segundos. O código a seguir está disponível em 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();
}

}

Nota: este código não é otimizado de todo. É apenas uma coisa rápida que escrevi, mas, ei, funciona!

    
por utybo 04.08.2016 / 16:16