@ -87,19 +87,23 @@ public class PlayerController {
private ImageView pause_black = new ImageView ( new Image ( "icons/ic_pause_black_24dp_1x.png" ) ) ;
private ImageView fullscreen_black = new ImageView ( new Image ( "icons/ic_fullscreen_black_24dp_1x.png" ) ) ;
private ImageView fullscreen_exit_black = new ImageView ( new Image ( "icons/ic_fullscreen_exit_black_24dp_1x.png" ) ) ;
/ * * FIXME double set currentTime ( )
* initialize the new PlayerWindow
* @param entry the film object
* @param player the player object ( needed for closing action )
* @param dbController the dbController object
/ * *
* create a new PlayerWindow object
* @param mainWCon the MainWindowController TODO do we need this ?
* @param player the player object ( needed for closing action )
* @param film the film object
* /
public void init ( MainWindowController mainWCon , Player player , FilmTabelDataType film ) {
public PlayerController ( MainWindowController mainWCon , Player player , FilmTabelDataType film ) {
this . mainWCon = mainWCon ;
this . player = player ;
this . film = film ;
startTime = mainWCon . getDbController ( ) . getCurrentTime ( film . getStreamUrl ( ) ) ;
autoplay = mainWCon . isAutoplay ( ) ;
}
/ * *
* initialize the PlayerWindow
* /
public void init ( ) {
initActions ( ) ;
if ( film . getStreamUrl ( ) . startsWith ( "http" ) ) {
@ -107,9 +111,8 @@ public class PlayerController {
} else {
media = new Media ( new File ( film . getStreamUrl ( ) ) . toURI ( ) . toString ( ) ) ;
}
startTime = mainWCon . getDbController ( ) . getCurrentTime ( film . getStreamUrl ( ) ) ;
autoplay = mainWCon . isAutoplay ( ) ;
// create the MediaPlayer object
mediaPlayer = new MediaPlayer ( media ) ;
mediaView . setPreserveRatio ( true ) ;
mediaView . setMediaPlayer ( mediaPlayer ) ;
@ -120,16 +123,26 @@ public class PlayerController {
width . bind ( Bindings . selectDouble ( mediaView . sceneProperty ( ) , "width" ) ) ;
height . bind ( Bindings . selectDouble ( mediaView . sceneProperty ( ) , "height" ) ) ;
startTime = mainWCon . getDbController ( ) . getCurrentTime ( film . getStreamUrl ( ) ) ;
autoplay = mainWCon . isAutoplay ( ) ;
season = ! film . getSeason ( ) . isEmpty ( ) ? Integer . parseInt ( film . getSeason ( ) ) : 0 ;
episode = ! film . getEpisode ( ) . isEmpty ( ) ? Integer . parseInt ( film . getEpisode ( ) ) : 0 ;
// nextEpBtn.setStyle("-fx-button-type: RAISED; -fx-background-color: #" + mainWCon.getColor() + "; -fx-text-fill: WHITE;");
initMediaPlayer ( ) ;
// set the control elements to the correct value
stopBtn . setGraphic ( stop_black ) ;
playBtn . setGraphic ( pause_black ) ;
fullscreenBtn . setGraphic ( fullscreen_exit_black ) ;
timeSlider . setValue ( 0 ) ;
}
private void initMediaPlayer ( ) {
// start the media if the player is ready
mediaPlayer . setOnReady ( new Runnable ( ) {
@Override
public void run ( ) {
duration = media . getDuration ( ) . toMillis ( ) ;
timeSlider . setMax ( ( duration / 1000 ) / 60 ) ;
mediaPlayer . play ( ) ;
@ -146,17 +159,17 @@ public class PlayerController {
if ( timeToEnd < 20000 & & episode ! = 0 & & autoplay ) {
// show 20 seconds before the end a button (next episode in 10 seconds)
if ( ! nextEpBtn . isVisible ( ) )
if ( ! nextEpBtn . isVisible ( ) )
nextEpBtn . setVisible ( true ) ;
if ( countdown ! = ( int ) ( ( timeToEnd - 10000 ) / 1000 ) ) {
countdown = ( int ) ( ( timeToEnd - 10000 ) / 1000 ) ;
if ( countdown ! = ( int ) ( ( timeToEnd - 10000 ) / 1000 ) ) {
countdown = ( int ) ( ( timeToEnd - 10000 ) / 1000 ) ;
nextEpBtn . setText ( "next episode in " + countdown + " seconds" ) ; // TODO translate
bottomVBox . setVisible ( true ) ;
}
}
// if we are end time -10 seconds, do autoplay, if activated
if ( timeToEnd < 10000 ) {
if ( timeToEnd < 10000 ) {
nextEpBtn . setVisible ( false ) ;
autoPlayNewFilm ( ) ;
}
@ -166,25 +179,16 @@ public class PlayerController {
mainWCon . getDbController ( ) . setCurrentTime ( film . getStreamUrl ( ) , 0 ) ; // reset old video start time
playBtn . setGraphic ( play_arrow_black ) ;
} else {
if ( nextEpBtn . isVisible ( ) )
if ( nextEpBtn . isVisible ( ) )
nextEpBtn . setVisible ( false ) ;
}
if ( ! mousePressed ) {
timeSlider . setValue ( ( currentTime / 1000 ) / 60 ) ;
// int sec = (int)(currentTime / 1000);
// int min = (int) TimeUnit.SECONDS.toMinutes(sec);
// int remSec = sec - (int)TimeUnit.MINUTES.toSeconds(min);
// System.out.println("\nTime: " + min + ":" + remSec);
}
}
} ) ;
// set the control elements to the correct value
stopBtn . setGraphic ( stop_black ) ;
playBtn . setGraphic ( pause_black ) ;
fullscreenBtn . setGraphic ( fullscreen_exit_black ) ;
timeSlider . setValue ( 0 ) ;
}
/ * *
@ -288,7 +292,8 @@ public class PlayerController {
FilmTabelDataType nextFilm = mainWCon . getDbController ( ) . getNextEpisode ( film . getTitle ( ) , episode , season ) ;
if ( nextFilm ! = null ) {
mediaPlayer . stop ( ) ;
init ( mainWCon , player , nextFilm ) ;
film = nextFilm ;
init ( ) ;
autoplay = true ;
}
}