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 (406)
games submitted by our members
Games in WIP (293)
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 288 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!
 
Browse for soundtracks 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!
cubemaster21 (73 views)
2013-05-17 21:29:12

alaslipknot (85 views)
2013-05-16 21:24:48

gouessej (114 views)
2013-05-16 00:53:38

gouessej (109 views)
2013-05-16 00:17:58

theagentd (120 views)
2013-05-15 15:01:13

theagentd (109 views)
2013-05-15 15:00:54

StreetDoggy (154 views)
2013-05-14 15:56:26

kutucuk (176 views)
2013-05-12 17:10:36

kutucuk (173 views)
2013-05-12 15:36:09

UnluckyDevil (182 views)
2013-05-12 05:09:57
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

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.165 seconds with 21 queries.