Pessoal, preciso executar um vídeo da seguinte maneira:
Ao selecionar uma linha em um Jtable, a String obtida acrescentada de “.MPG” forma o nome do arquivo a ser aberto
Quando clico na JTable, a janela do vídeo abre, mas nada é executado. Seria problema com a conversão de variáveis?
private void Carregar_Video() {
int x = minha_tabela.getSelectedRow();
String linha_selecionada = (String) minha_tabela.getValueAt(x, 0);
String caminho = "/videos/" + linha_selecionada + ".MPG";
File arquivo = new File(caminho);
URL arquivoURL = null;
try {
arquivoURL = arquivo.toURL();
} catch (MalformedURLException malformedURLException) {
System.err.println("Erro na criação da URL");
}
if (arquivoURL != null) {
JFrame jan_video = new JFrame(linha_selecionada);
jan_video.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Carregar_Video mediaPanel = new Carregar_Video (arquivoURL);
jan_video.add(mediaPanel);
jan_video.setSize(400, 300);
jan_video.setLocation(750, 430);
jan_video.setVisible(true);
}
}
import java.awt.BorderLayout;
import java.awt.Component;
import java.io.IOException;
import java.net.URL;
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.swing.JPanel;
public class Carregar_Video_Janela extends JPanel {
public Carregar_Video_Janela(URL arquivoURL) {
setLayout(new BorderLayout());
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
try {
Player mediaPlayer = Manager.createRealizedPlayer(arquivoURL);
Component video = mediaPlayer.getVisualComponent();
Component controls = mediaPlayer.getControlPanelComponent();
if (video != null) {
add(video, BorderLayout.CENTER);
}
if (controls != null) {
add(controls, BorderLayout.SOUTH);
}
mediaPlayer.start();
} catch (NoPlayerException noPlayerException) {
System.err.println("Media Player não Encontrado");
} catch (CannotRealizeException cannotRealizeException) {
System.err.println("Não foi Possível Executar o Media Player");
} catch (IOException iOException) {
System.err.println("Erro na Leitura do Arquivo");
}
}
}