Erro na reprodução de arquivos de video com JMF

0 respostas
F

E ai galera tudo bem ?

Bom eu tenho um erro que eu não sei em qual área se encaixa
por isso que na dúvida eu resolvi postar aqui. Caso o tópico
esteja no lugar errado me desculpem.

Bom o negócio é o seguinte:
Eu estou estudando um pouco sobre o Java Media Framework.
Para isso resolvi fazer um Media Player, mas eu não consigo
abrir arquivos de video direito. Alguns só rodam o som,
outros só a imagem.

Aí vai código:

package Player;

import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;

import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JFileChooser;

import javax.media.Manager;
import javax.media.Player;
import javax.media.NoPlayerException;
import javax.media.CannotRealizeException;




public class FPlayer extends JFrame{
	
	private Container container;
	
	private JPanel painel;
	private JMenuBar menu;
	private JMenu menuFile;
	private JMenuItem item;
	private JFileChooser openDialog;
	private Player pl1;
	
	private int state;
	private static Dimension k;
	
	
	public FPlayer(){
		
		super ("Player");
		painel = new JPanel();
		menu = new JMenuBar();
		menuFile = new JMenu("File");
		item = new JMenuItem("Abrir Arquivo");
		menu.add(menuFile);
		menuFile.add(item);
		openDialog = new JFileChooser();
		
		container = getContentPane();
		setJMenuBar(menu);	
        	 
			item.addActionListener(
		
				
				new ActionListener(){
					
					public void actionPerformed( ActionEvent event){
						
						int result = openDialog.showOpenDialog(null);						
						if (result == JFileChooser.CANCEL_OPTION)
							return;
						
						
						try{
							if(state == Player.Started){
								pl1.stop();
								pl1.close();
								getContentPane().removeAll();
							}
								
							else
								state = Player.Started;
								
							File file = openDialog.getSelectedFile();
							URL url = file.toURL();
							pl1 = Manager.createRealizedPlayer( url );
							Component video = pl1.getVisualComponent();
					        Component controls = pl1.getControlPanelComponent();
					        
					        if ( video != null ) 
					        	container.add( video, BorderLayout.CENTER );

					         if ( controls != null ) {
					        	 container.add( controls, BorderLayout.SOUTH );
					        	 
					         pl1.start();
					         FPlayer.this.setSize(401,400);
					         }
						}
						catch(MalformedURLException mue){
							mue.printStackTrace();
						}
						catch(NoPlayerException npe){
							npe.printStackTrace();
						}
						catch(CannotRealizeException cre){
							cre.printStackTrace();
						}
						catch(IOException ioe){
							ioe.printStackTrace();
						}
					}
					
				}
				
			);

        pl1 = null;
		
	}
	
	
	
	public static void main(String args[]){
		
		FPlayer myplayer = new FPlayer();
		myplayer.setDefaultCloseOperation(EXIT_ON_CLOSE);	
		myplayer.setSize(400,400);
		myplayer.setVisible(true);
		
	}

	

}

Eu pesquisei na internet mas achei coisas muito vagas sobre o JMF.
Será que alguém pode me ajudar ? Ou me dar dicas de um bom
material sobre o assunto, ou os dois…

Desde já agradeço.

Criado 5 de novembro de 2007
Respostas 0
Participantes 1