-
August 9th, 2013, 03:36 AM
#1
java frame help
I currently have a code to display video playback and it works but i want to instead of having it play in its own window i want it to play from in my Jframe. Here's the code thanks...
Code:
import javax.swing.*;
import javax.media.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import javax.swing.text.*;
import java.net.URL;
public class JPlayer extends JFrame
{
private JPanel mainPanel;
public JPlayer( URL mediaURL )
{
Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
try
{
Player mediaPlayer = Manager.createRealizedPlayer( mediaURL );
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( "No media player found" );
}
catch ( CannotRealizeException cannotRealizeException )
{
System.err.println( "Could not realize media player" );
}
catch ( IOException iOException )
{
System.err.println( "Error reading from the source" );
}
mainPanel = new JPanel();
getContentPane().add(mainPanel);
mainPanel.setLayout(null);
setTitle("Josh Player");
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
this.setExtendedState(Frame.MAXIMIZED_BOTH);
}
public static void main(String[] args)
{
JFileChooser fileChooser = new JFileChooser();
// show open file dialog
int result = fileChooser.showOpenDialog( null );
if ( result == JFileChooser.APPROVE_OPTION ) // user chose a file
{
URL mediaURL = null;
try
{
// get the file as URL
mediaURL = fileChooser.getSelectedFile().toURL();
} // end try
catch ( MalformedURLException malformedURLException )
{
System.err.println( "Could not create URL for the file" );
} // end catch
if ( mediaURL != null ) // only display if there is a valid URL
{
JFrame mediaTest = new JFrame( "Media Tester" );
mediaTest.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
MediaPanel mediaPanel = new MediaPanel( mediaURL );
mediaTest.add( mainPanel );
// mediaTest.setSize( 300, 300 );
//mediaTest.setVisible( true );
}
}
//JPlayer jp = new JPlayer();
//MediaPanel mediaPanel = new MediaPanel( mediaURL );
//mainPanel.add( mediaPanel );
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|