@ -32,6 +32,10 @@ import org.mosad.homeflix.controller.XMLController;
import org.mosad.homeflix.datatypes.FilmTabelDataType ;
import com.jfoenix.controls.JFXButton ;
import com.jfoenix.controls.JFXDialogLayout ;
import com.jfoenix.controls.JFXPopup ;
import com.jfoenix.controls.JFXPopup.PopupHPosition ;
import com.jfoenix.controls.JFXPopup.PopupVPosition ;
import com.jfoenix.controls.JFXSlider ;
import javafx.application.Platform ;
@ -48,9 +52,11 @@ import javafx.scene.image.PixelBuffer;
import javafx.scene.image.PixelFormat ;
import javafx.scene.image.WritableImage ;
import javafx.scene.input.MouseEvent ;
import javafx.scene.layout.AnchorPane ;
import javafx.scene.layout.HBox ;
import javafx.scene.layout.VBox ;
import javafx.scene.media.MediaView ;
import javafx.scene.text.Text ;
import uk.co.caprica.vlcj.factory.MediaPlayerFactory ;
import uk.co.caprica.vlcj.player.base.MediaPlayer ;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer ;
@ -63,6 +69,7 @@ import uk.co.caprica.vlcj.player.embedded.videosurface.callback.format.RV32Buffe
public class PlayerController {
@FXML private AnchorPane panePlayer ;
@FXML private MediaView mediaView ;
@FXML private ImageView videoImageView ;
@ -77,8 +84,9 @@ public class PlayerController {
@FXML private JFXButton btnPlay ;
@FXML private JFXButton btnReplay ;
@FXML private JFXButton btnForward ;
@FXML private JFXButton fullscreenBtn ;
@FXML private JFXButton nextEpBtn ;
@FXML private JFXButton btnAudio ;
@FXML private JFXButton btnFullscreen ;
@FXML private JFXButton btnNextEpisode ;
@FXML private ImageView stopIcon ;
@FXML private ImageView playIcon ;
@ -141,7 +149,7 @@ public class PlayerController {
initPlayerWindow ( ) ;
initMediaPlayer ( ) ;
initSlider ( ) ;
initTime Slider ( ) ;
}
/ * *
@ -184,9 +192,22 @@ public class PlayerController {
} ) ;
}
/ * *
* initialize the embedded media player
* /
private void initMediaPlayer ( ) {
embeddedMediaPlayer . events ( ) . addMediaPlayerEventListener ( new HFMediaPlayerEventListener ( ) {
@Override
public void mediaPlayerReady ( MediaPlayer mediaPlayer ) {
System . out . println ( mediaPlayer . audio ( ) . trackCount ( ) ) ;
mediaPlayer . audio ( ) . trackDescriptions ( ) . forEach ( trackDesc - > {
System . out . println ( trackDesc . description ( ) ) ;
} ) ;
}
@Override
public void timeChanged ( MediaPlayer mediaPlayer , long newTime ) {
currentTime = newTime ;
@ -211,7 +232,10 @@ public class PlayerController {
} ) ;
}
private void initSlider ( ) {
/ * *
* initialize the time slider
* /
private void initTimeSlider ( ) {
// if the mouse on the timeSlider is released, skip to the new position
timeSlider . setOnMouseReleased ( new EventHandler < MouseEvent > ( ) {
@Override
@ -228,7 +252,7 @@ public class PlayerController {
}
} ) ;
// get the new skip time
// on value change, get the new skip time
timeSlider . valueProperty ( ) . addListener ( new ChangeListener < Number > ( ) {
@Override
public void changed ( ObservableValue < ? extends Number > ov , Number old_val , Number new_val ) {
@ -242,6 +266,10 @@ public class PlayerController {
embeddedMediaPlayer . controls ( ) . skipTime ( ( long ) startTime ) ; // skipt to the start time
}
/ * *
* Stop and release the media player .
* Always call this method to stop the media player .
* /
public void stop ( ) {
DBController . getInstance ( ) . setCurrentTime ( media . getStreamUrl ( ) , embeddedMediaPlayer . status ( ) . time ( ) ) ;
embeddedMediaPlayer . controls ( ) . stop ( ) ;
@ -269,16 +297,16 @@ public class PlayerController {
if ( endTime < 31000 & & episode ! = 0 & & autoplay ) {
int countdown = ( int ) ( ( endTime / 1000 ) - 20 ) ; // a 10 seconds countdown
if ( ! nextEpBtn . isVisible ( ) ) {
nextEpBtn . setVisible ( true ) ;
if ( ! btnNextEpisode . isVisible ( ) ) {
btnNextEpisode . setVisible ( true ) ;
}
if ( endTime > 20000 ) {
nextEpBtn . setText ( XMLController . getLocalBundle ( ) . getString ( "nextEpisode" )
btnNextEpisode . setText ( XMLController . getLocalBundle ( ) . getString ( "nextEpisode" )
+ countdown + XMLController . getLocalBundle ( ) . getString ( "seconds" ) ) ;
bottomVBox . setVisible ( true ) ;
} else {
nextEpBtn . setVisible ( false ) ;
btnNextEpisode . setVisible ( false ) ;
playNextMedia ( ) ;
}
}
@ -312,7 +340,22 @@ public class PlayerController {
}
@FXML
void fullscreenBtnAction ( ActionEvent event ) {
void btnAudioAction ( ActionEvent event ) {
// TODO move to separate class "AudioPopup"
JFXDialogLayout content = new JFXDialogLayout ( ) ;
content . setHeading ( new Text ( "Test" ) ) ;
content . setBody ( new Text ( "Hallo 123" ) ) ;
content . setPrefSize ( 150 , 200 ) ;
JFXPopup popup = new JFXPopup ( ) ;
popup . setPopupContent ( content ) ;
popup . show ( btnAudio , PopupVPosition . BOTTOM , PopupHPosition . RIGHT ,
0 , - 1 * bottomVBox . getHeight ( ) ) ;
}
@FXML
void btnFullscreenAction ( ActionEvent event ) {
if ( player . getStage ( ) . isFullScreen ( ) ) {
player . getStage ( ) . setFullScreen ( false ) ;
fullscreenIcon . setImage ( fullscreen ) ;
@ -323,8 +366,8 @@ public class PlayerController {
}
@FXML
void nextEpBtn Action( ActionEvent event ) {
nextEpBtn . setVisible ( false ) ;
void btnNextEpisode Action( ActionEvent event ) {
btnNextEpisode . setVisible ( false ) ;
playNextMedia ( ) ;
}