4 Replies - 1192 Views - Last Post: 04 February 2013 - 10:42 AM Rate Topic: -----

#1 VIPERHlr  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 85
  • Joined: 05-August 11

Embed Video Into Java Program

Posted 02 February 2013 - 06:32 AM

Hi, I have a project that I am working on. I have a video and I want it to be played within my java program with pause,start buttons etc, something like a media player. My question is, How do I go about doing this?, Is their some plug in that I need to use?. Please can someone help because I completely do not know where to start. This is the first time that I am doing something this big.
Is This A Good Question/Topic? 0
  • +

Replies To: Embed Video Into Java Program

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Embed Video Into Java Program

Posted 02 February 2013 - 08:03 AM

Check out the FMJ library

Or even better you can use JavaFX (the new replacement for Swing). It has built in support for media playback etc. Take a look at this.
Was This Post Helpful? 2
  • +
  • -

#3 VIPERHlr  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 85
  • Joined: 05-August 11

Re: Embed Video Into Java Program

Posted 04 February 2013 - 10:27 AM

Thanks bro, one problem though, why does the video play like this:

Posted Image

This post has been edited by VIPERHlr: 04 February 2013 - 10:28 AM

Was This Post Helpful? 0
  • +
  • -

#4 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Embed Video Into Java Program

Posted 04 February 2013 - 10:29 AM

Well I haven't got a clue as you haven't said how you're doing it.

Are you sure the video component fits the entire frame?
Was This Post Helpful? 0
  • +
  • -

#5 VIPERHlr  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 85
  • Joined: 05-August 11

Re: Embed Video Into Java Program

Posted 04 February 2013 - 10:42 AM

Yes it does, heres my code:

package javafxapplication1;

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 pc
 */
public class JavaFXApplication1 extends Application {
    public static void main(String[]args)
    {
        launch(args);
    }
    @Override
    public void start(final Stage stage)throws Exception
    {
        Group root = new Group();
        
        Media media = new Media("file:/Users/pc/Desktop/Video.mp4");
        final MediaPlayer player = new MediaPlayer(media);
        MediaView view = new MediaView(player);
        
        System.out.println("media.width: "+media.getWidth());
        
        root.getChildren().add(view);
        Scene scene = new Scene(root,400,400,Color.BLACK);
        stage.setScene(scene);
        stage.show();
        
        player.play();
        player.setOnReady(new Runnable()
        {
            @Override
            public void run()
            {
                int w = player.getMedia().getWidth();
                int h = player.getMedia().getHeight();
                
                stage.setMinWidth(w);
                stage.setMaxHeight(h);
            }
        });
    }

    }

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1