Skip to content

Commit

Permalink
add ui
Browse files Browse the repository at this point in the history
  • Loading branch information
willard committed Sep 25, 2019
1 parent 565962f commit f3eecca
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jplayer.player.component;

import com.jplayer.demo.vlctest.JavaFXDirectRenderingTest;
import javafx.application.Platform;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
Expand All @@ -10,6 +9,7 @@
import javafx.scene.image.WritableImage;
import javafx.scene.image.WritablePixelFormat;
import javafx.scene.layout.BorderPane;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.scene.transform.Affine;
import uk.co.caprica.vlcj.factory.MediaPlayerFactory;
Expand All @@ -31,7 +31,6 @@
*/
public class VlcMediaPlayer extends BorderPane{


private String VIDEO_FILE = "C:\\devFile\\操作系统原理02.wmv";
// private String VIDEO_FILE = "D:\\2.mp4";
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,67 @@
package com.jplayer.player.controller;

import com.jplayer.player.component.EventListener;
import com.jplayer.player.component.VlcMediaPlayer;
import com.sun.jna.NativeLibrary;
import javafx.animation.AnimationTimer;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import uk.co.caprica.vlcj.binding.RuntimeUtil;
import uk.co.caprica.vlcj.player.base.MediaPlayer;
import uk.co.caprica.vlcj.player.embedded.videosurface.callback.BufferFormat;

import java.nio.ByteBuffer;

/**
* @author Willard
* @date 2019/9/24
*/
public class CourseMainController {
public class CourseMainController implements EventListener {
@FXML
private VBox chapterBox;
private BorderPane mainPane;
private VlcMediaPlayer mediaPlayer;
private AnimationTimer timer;

@FXML
private BorderPane centerPane;
private VBox chapterBox;

public void initialize() {
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\devFile\\vlc");

this.timer = new AnimationTimer() {
@Override
public void handle(long now) {
mediaPlayer.renderFrame();
}
};

BorderPane centerPane = new BorderPane();
Image img1 = new Image(getClass().getResourceAsStream("/images/test.jpg"));
ImageView view1 = new ImageView(img1);
this.centerPane.setCenter(view1);
centerPane.setCenter(view1);
this.mainPane.setCenter(centerPane);
setChapter();
}
void setChapter(){
Button btn1 = new Button();

btn1.setId("1");
btn1.setText("视频");
btn1.setOnMouseClicked(e->{
changeToVedio();
});
btn1.setId("1");
btn1.setText("视频");

Button btn2 = new Button();
btn2.setId("2");
btn2.setText("图片");
btn2.setOnMouseClicked(e->{
changeToPic();
});


Button btn3 = new Button();
btn3.setId("1");
Expand All @@ -53,11 +81,33 @@ void setChapter(){
}

private void changeToVedio(){
System.out.println("切换");
// this.centerPane = new BorderPane();
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\devFile\\vlc");

mediaPlayer = new VlcMediaPlayer(this);

this.mainPane.setCenter(mediaPlayer);
this.mediaPlayer.startPlay();
this.timer.start();
}

private void changeToPic(){
this.mediaPlayer.stopPlay();
this.timer.stop();

BorderPane centerPane1 = new BorderPane();
Image img1 = new Image(getClass().getResourceAsStream("/images/test1.jpg"));
ImageView view1 = new ImageView(img1);
this.centerPane.setCenter(view1);
centerPane1.setCenter(view1);
this.mainPane.setCenter(centerPane1);
}

@Override
public void display(MediaPlayer mediaPlayer, ByteBuffer[] nativeBuffers, BufferFormat bufferFormat) {

}

@Override
public void bufferFormat(int sourceWidth, int sourceHeight) {

}
}
3 changes: 1 addition & 2 deletions src/main/resources/views/CourseMain.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>
<BorderPane prefHeight="400.0" prefWidth="600.0" stylesheets="/styles/theme-select.css" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.jplayer.player.controller.CourseMainController">
<BorderPane prefHeight="400.0" prefWidth="600.0" fx:id="mainPane" stylesheets="/styles/theme-select.css" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.jplayer.player.controller.CourseMainController">
<left>
<VBox alignment="CENTER" styleClass="module-box" fx:id="chapterBox" spacing="30">
</VBox>
</left>
<center>
<BorderPane fx:id="centerPane"></BorderPane>
</center>
<bottom>
<!--<Button mnemonicParsing="false" onAction="#closeSystem" styleClass="exit_btn" BorderPane.alignment="CENTER_RIGHT" />-->
Expand Down

0 comments on commit f3eecca

Please sign in to comment.