Java Fx 2.0 Simple Media Player


In Java Fx 2.0 is fully a UI based Application in which we can easily create all types of desktop and web based component .Here i have explained a sample media player program which  it can play all type of you tube files.for running this application you need netbeans 7.1. with javafx 2.0
// Comment

package SimpleMediaPlayer;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 *
 * @author allinalljava.blogspot.com
 */
public class SimpleMediaPlayer extends Application {

    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

    @Override
  
    public void start(Stage stage) {
     //At First Step You have to create a Scence For Showing the Screen.
     Scene scene = new Scene(new Group(), 540, 209,Color.BLUEVIOLET);
     stage.setScene(scene);

     // Name and display the Stage.
     stage.setTitle("Welcome to Java Fx 2.0 Media Player Example");
     stage.show();
     // Create the media source. which is possible to get the file from the Embeddedjar itself
  
     Media media = new Media(SimpleMediaPlayer.class.getResource("You Belong To Me - JX.flv").toString());

     // Create the player for playing media.
     MediaPlayer mediaPlayer = new MediaPlayer(media);
     //set player property to autoplay
     mediaPlayer.setAutoPlay(true);

     // Create the view and add it to the Scene.
     MediaView mediaView = new MediaView(mediaPlayer);
     ((Group) scene.getRoot()).getChildren().add(mediaView);
 }
}
raja P Web Developer

2 comments:

  1. I copied this code but it doesn't work..

    ReplyDelete
  2. Initially the code failed. But when I used an .mp4 video file instead of a .flv file, The code ran PERFECTLY.
    Thank a lot mate...:)

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...