Question:

How to make a play list for a player using java.

by  |  earlier

0 LIKES UnLike

I want to make a play list for the following Java Player.

OneFile:

import java.io.File;

import java.net.MalformedURLException;

import java.net.URL;

import javax.swing.JFileChooser;

import javax.swing.JFrame;

class MediaTest

{

// launch the application

public static void main( String args[] )

{

// create a file chooser

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( mediaPanel );

mediaTest.setSize( 300, 300 );

mediaTest.setVisible( true );

} // end inner if

} // end outer if

} // end main

} // end class MediaTest

Another File:

import java.awt.BorderLayout;

import java.awt.Component;

import java.io.IOException;

import java.net.URL;

import javax.media.*;

import javax.swing.*;

class MediaPanel extends JPanel{

public MediaPanel(URL mediaURL){

setLayout(new BorderLayout());

Manager.setHint(Manager.LIGHTWEIGHT_...

try{

Player mediaPlayer = Manager.createRealizedPlayer(mediaURL);

Component video = mediaPlayer.getVisualComponent();

Component controls = mediaPlayer.getControlPanelComponent();

if(video != null)

add(video,BorderLayout.NORTH);

if(controls != null)

add(controls,BorderLayout.SOUTH);

mediaPlayer.start();

}

catch(NoPlayerException noPlayerException){

System.err.println("No media Player Found.");

}

catch(CannotRealizeException cannotRealizedException){

System.err.println("Can not realize media Player.");

}

catch(IOException iOException){

System.err.println("Error Reading From Sources.");

}

}

}

Please help............

 Tags:

   Report

1 ANSWERS


  1. OK.  I'm looking over you code.

    Yahoo! Answers is abbreviating some of your longer lines of code.  I can't get it to compile.  Do you want to re-post it in the following Swing forum.  And, if you use code-tags, the formatting of your source-code will be preserved, making the code more readable and understandable.

    Swing Forum on the JavaRanch.com:

    http://saloon.javaranch.com/cgi-bin/ubb/...

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.