package zizouz.crime.demo;

import java.io.File;

import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.event.ComponentListener;
import java.awt.event.ComponentEvent;

import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaPlayer.Status;
import javafx.scene.media.MediaView;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Paint;
import javafx.scene.Scene;

import javax.swing.JFrame;

public class VideoPlayer extends javafx.embed.swing.JFXPanel implements KeyListener, ComponentListener 
{
	private static final long serialVersionUID = 11521199786L;
	public static final String path = new File("./Resources/intro.mp4").toURI().toString();
	
	public VideoPlayer(String p) 
	{
		super();
		
		this.file = new Media(p);
		this.player = new MediaPlayer(this.file);
		this.view = new MediaView(this.player);
		
		this.pane = new BorderPane();
		this.fxScene = new Scene(this.pane);
		
		this.pane.setCenter(this.view);
		
		this.fxScene.setFill(Paint.valueOf("black"));
		
		this.addComponentListener(this);
		this.addKeyListener(this);
		this.componentResized(null);
		
		this.setScene(this.fxScene);
	}
	public VideoPlayer() 
	{
		this(VideoPlayer.path);
	}
	
	
	protected Media file;
	protected MediaPlayer player;
	protected MediaView view;
	protected BorderPane pane;
	protected Scene fxScene;
	
	protected volatile boolean auto;
	
	@Override
	public void keyPressed(KeyEvent event) 
	{
		
	}
	@Override
	public void keyReleased(KeyEvent event) 
	{
		switch (event.getKeyCode())
		{
			case KeyEvent.VK_SPACE:
				boolean playing = this.player.getStatus().equals(Status.PLAYING);
				if (playing) 
					this.player.pause();
				else
					this.player.play();
				return;
			case KeyEvent.VK_ENTER:
				boolean playing = this.player.getStatus().equals(Status.PLAYING);
				this.player.stop();
				if (playing)
					this.player.play();
				return;
			case KeyEvent.VK_A:
				if (this.auto)
					this.auto = false;
				else
					this.auto = true;
				
				this.player.setAutoPlay(this.auto);
		}
	}
	@Override
	public void keyTyped(KeyEvent event) 
	{
		
	}
	@Override
	public void componentResized(ComponentEvent event) 
	{
		this.view.setPreserveRatio(true);
		this.view.setFitWidth(this.getWidth());
		this.view.setFitHeight(this.getHeight());
	}
	@Override
	public void componentMoved(ComponentEvent event) 
	{
		
	}
	@Override
	public void componentMoved(ComponentEvent event) 
	{
		
	}
	@Override
	public void componentShown(ComponentEvent event) 
	{
		
	}
	@Override
	public void componentHidden(ComponentEvent event) 
	{
		
	}
	@Override
	protected void finalize() 
	{
		this.player.dispose();
		this.file = null;
		this.player = null;
		this.view = null;
		this.pane = null;
		this.fxScene = null;
		
	}
	// For Testing
	public static void main(String[] args) 
	{
		String p;
		VideoPlayer player;
		
		if (args.length > 0)
			p = args[0];
			
		if (p != null)
			player = new VideoPlayer(p);
		else
			player = new VideoPlayer();
			
		javax.swing.JFrame f = new javax.swing.JFrame();
		
		f.add(p);
		p.player.play();
		f.getContentPane().setBackground(java.awt.Color.BLACK);
		f.setLocationRelativeTo(null);
		f.pack();
		
		f.add(new java.awt.KeyAdapter() {
			@Override public void keyReleased(KeyEvent event) 
			{
				if (event.getKeyCode() == KeyEvent.VK_ESCAPE)
					com.apple.eawt.Application.getApplication().requestToggleFullScreen(f);
			}
		});
		
		com.apple.eawt.FullScreenUtilities.setWindowCanFullScreen(f, true);
		
		if (args.length > 1)
		{
			if (args[1] != "-f")
				f.setVisible(true);
				return;
			
			f.setVisible(true);
			
			com.apple.eawt.Application.getApplication().requestToggleFullScreen(f);
			com.apple.eawt.Application.getApplication().requestForeground(true);
			
		}
		
	}
	
	
	
	
	
	
	
	
	
}

@@ -449,36 +449,8 @@
 e;%0A%0A
-import javax.swing.JFrame;%0A%0A
 publ
@@ -672,13 +672,14 @@
 ces/
-intro
+startO
 .mp4
@@ -1763,39 +1763,37 @@
 ER:%0A%09%09%09%09boolean 
-playing
+inter
  = this.player.g
@@ -1859,23 +1859,21 @@
 %09%09%09%09if (
-playing
+inter
 )%0A%09%09%09%09%09t
@@ -2390,79 +2390,8 @@
 ide%0A
-%09public void componentMoved(ComponentEvent event) %0A%09%7B%0A%09%09%0A%09%7D%0A%09@Override%0A
 %09pub
@@ -2766,16 +2766,23 @@
 String p
+ = null
 ;%0A%09%09Vide
@@ -3001,14 +3001,24 @@
 dd(p
+layer
 );%0A%09%09p
+layer
 .pla
@@ -3087,16 +3087,28 @@
 BLACK);%0A
+%09%09f.pack();%0A
 %09%09f.setL
@@ -3138,28 +3138,27 @@
 ;%0A%09%09
-f.pack();%0A%09%09%0A%09%09f.add
+%0A%09%09f.addKeyListener
 (new
@@ -3167,16 +3167,22 @@
 ava.awt.
+event.
 KeyAdapt
@@ -3510,17 +3510,41 @@
  != %22-f%22
-)
+ && args%5B0%5D != %22-f%22)%0A%09%09%09%7B
 %0A%09%09%09%09f.s
@@ -3572,16 +3572,21 @@
 return;%0A
+%09%09%09%7D%0A
 %09%09%09%0A%09%09%09f
@@ -3769,25 +3769,33 @@
 %7D%0A%09%09
-%0A%09%7D%0A%09%0A%09%0A%09%0A%09
+f.setVisible(true);
 %0A%09
-%0A
 %09%0A%09
+%7D
 %0A%09%0A%09

Update VideoPlayer.java