Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (416)
games submitted by our members
Games in WIP (306)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Video with JavaFX: How to paint on custom component?  (Read 370 times)
0 Members and 1 Guest are viewing this topic.
Offline Serethos

Junior Member




Java games rock!


« Posted 2013-02-19 00:22:02 »

Hey guys,

after trying godzillions of video-playback approaches, I returned to give JavaFX a try. There have been a few recent updates on tutorials and indeed, there is one working (still have to prove it for Mac and Linux through). My problem is that I want to display the video on a custom component. In my case that component is the UI of Slick2D. Can anyone hint me if there is a simple way to either paint the video on any graphics context or just create a frame and then grab it?
The code I made run from the turorial is like that:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
public class FxVideoSwingTest {

     private static void initAndShowGUI() {
         // This method is invoked on Swing thread
        JFrame frame = new JFrame("FX");
         final JFXPanel fxPanel = new JFXPanel();
         frame.add(fxPanel);
         frame.setVisible(true);
         frame.setSize(800, 600);

         Platform.runLater(new Runnable() {
             @Override
             public void run() {
                 initFX(fxPanel);
             }
         });
     }

    private static final String   MEDIA_URL   = "file:///eclipse_workspace/JavaFxVideo/head.mp4";

     
     private static void initFX(JFXPanel fxPanel) {
       // Create media player
      Media media = new Media(MEDIA_URL);
       javafx.scene.media.MediaPlayer mediaPlayer = new javafx.scene.media.MediaPlayer(media);
       mediaPlayer.setAutoPlay(true);
       mediaPlayer.setCycleCount(javafx.scene.media.MediaPlayer.INDEFINITE);

       // Print track and metadata information
      media.getTracks().addListener(new ListChangeListener<Track>()
       {
          @Override
          public void onChanged(Change<? extends Track> change)
          {
             System.out.println("Track> " + change.getList());
          }
       });
       media.getMetadata().addListener(new MapChangeListener<String, Object>()
       {
          @Override
          public void onChanged(MapChangeListener.Change<? extends String, ? extends Object> change)
          {
             System.out.println("Metadata> " + change.getKey() + " -> " + change.getValueAdded());
          }
       });
         // This method is invoked on JavaFX thread
       Group root = new Group();
         Scene scene =  new Scene(root, 800, 600);
         MediaView mediaView = new MediaView(mediaPlayer);
         root.getChildren().add(mediaView);
         fxPanel.setScene(scene);
     }

     public static void main(String[] args) {
         SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                 initAndShowGUI();
             }
         });
     }
 }
Pages: [1]
  ignore  |  Print  
 
 

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
BrassApparatus (7 views)
2013-06-19 08:52:37

NegativeZero (11 views)
2013-06-19 03:31:52

NegativeZero (14 views)
2013-06-19 03:24:09

Jesse_Attard (19 views)
2013-06-18 22:03:02

HeroesGraveDev (60 views)
2013-06-15 23:35:23

Vermeer (59 views)
2013-06-14 20:08:06

davedes (59 views)
2013-06-14 16:03:55

alaslipknot (53 views)
2013-06-13 07:56:31

Roquen (74 views)
2013-06-12 04:12:32

alaslipknot (58 views)
2013-06-10 19:30:18
Smoothing Algorithm Question
by UprightPath
2013-05-28 02:58:26

Smoothing Algorithm Question
by UprightPath
2013-05-28 02:57:33

Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!