Browse Source

fix player resolution mismatch

dev
Jannik 2 years ago
parent
commit
e29bcc5da3
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 69
      src/main/java/org/mosad/homeflix/player/PlayerController.java

69
src/main/java/org/mosad/homeflix/player/PlayerController.java

@ -60,10 +60,12 @@ import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.media.MediaView;
import javafx.scene.text.Text;
import javafx.util.StringConverter;
import uk.co.caprica.vlcj.factory.MediaPlayerFactory;
import uk.co.caprica.vlcj.media.Media;
import uk.co.caprica.vlcj.media.MediaEventAdapter;
import uk.co.caprica.vlcj.media.MediaParsedStatus;
import uk.co.caprica.vlcj.player.base.MediaPlayer;
import uk.co.caprica.vlcj.player.base.TrackDescription;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
@ -86,7 +88,6 @@ 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;
@FXML private HBox hBoxTop;
@ -128,6 +129,7 @@ public class PlayerController {
private int season = 0;
private int episode = 0;
private boolean mousePressed = false;
private boolean showControls = true;
private boolean autoplay;
@ -139,6 +141,10 @@ public class PlayerController {
private JFXPopup audioPopup;
// fix wrong buffer resolution
private int videoWidth = 0;
private int videoHeigth = 0;
/**
* create a new PlayerWindow object
* @param player the player object (needed for closing action)
@ -165,8 +171,13 @@ public class PlayerController {
season = !media.getSeason().isEmpty() ? Integer.parseInt(media.getSeason()) : 0;
episode = !media.getEpisode().isEmpty() ? Integer.parseInt(media.getEpisode()) : 0;
lblTitle.setText(media.getTitle());
if (episode > 0) {
// if the media is a TV show, add season + episode to the title
lblTitle.setText(media.getTitle() + " S" + season + ":E" + episode);
} else {
lblTitle.setText(media.getTitle());
}
initPlayerWindow();
initMediaPlayer();
initTimeSlider();
@ -245,7 +256,20 @@ public class PlayerController {
duration = newLength;
timeSlider.setMax(duration / 1000);
}
});
embeddedMediaPlayer.events().addMediaEventListener(new MediaEventAdapter() {
@Override
public void mediaParsedChanged(Media media, MediaParsedStatus newStatus) {
super.mediaParsedChanged(media, newStatus);
videoWidth = embeddedMediaPlayer.video().videoDimension().width;
videoHeigth= embeddedMediaPlayer.video().videoDimension().height;
// start the video
embeddedMediaPlayer.media().play(media.newMediaRef());
embeddedMediaPlayer.controls().skipTime((long) startTime); // skip to the start time
}
});
}
@ -317,9 +341,11 @@ public class PlayerController {
// animatedThumb.getChildren().add(iv);
}
// Start the parsing the media meta data
public void start() {
embeddedMediaPlayer.media().play(media.getStreamUrl());
embeddedMediaPlayer.controls().skipTime((long) startTime); // skipt to the start time
// parse meta data
embeddedMediaPlayer.media().prepare(media.getStreamUrl());
embeddedMediaPlayer.media().parsing().parse();
}
/**
@ -433,13 +459,8 @@ public class PlayerController {
@FXML
void btnFullscreenAction(ActionEvent event) {
if (player.getStage().isFullScreen()) {
player.getStage().setFullScreen(false);
fullscreenIcon.setImage(fullscreen);
} else {
player.getStage().setFullScreen(true);
fullscreenIcon.setImage(fullscreenExit);
}
player.getStage().setFullScreen(!player.getStage().isFullScreen());
fullscreenIcon.setImage(player.getStage().isFullScreen() ? fullscreenExit : fullscreen);
}
@FXML
@ -483,21 +504,20 @@ public class PlayerController {
}
private class FXBufferFormatCallback implements BufferFormatCallback {
private int sourceWidth;
private int sourceHeight;
@Override
public BufferFormat getBufferFormat(int sourceWidth, int sourceHeight) {
this.sourceWidth = sourceWidth;
this.sourceHeight = sourceHeight;
public BufferFormat getBufferFormat(int sourceWidth, int sourceHeight) {
return new RV32BufferFormat(sourceWidth, sourceHeight);
}
@Override
public void allocatedBuffers(ByteBuffer[] buffers) {
assert buffers[0].capacity() == sourceWidth * sourceHeight * 4;
PixelFormat<ByteBuffer> pixelFormat = PixelFormat.getByteBgraPreInstance();
videoPixelBuffer = new PixelBuffer<>(sourceWidth, sourceHeight, buffers[0], pixelFormat);
// fixes buffer resolution, video resolution mismatch
videoPixelBuffer = new PixelBuffer<>(videoWidth, videoHeigth, buffers[0], pixelFormat);
//videoPixelBuffer = new PixelBuffer<>(sourceWidth, sourceHeight, buffers[0], pixelFormat);
videoImage = new WritableImage(videoPixelBuffer);
videoImageView.setImage(videoImage);
}
@ -506,11 +526,8 @@ public class PlayerController {
private class FXRenderCallback implements RenderCallback {
@Override
public void display(uk.co.caprica.vlcj.player.base.MediaPlayer mediaPlayer, ByteBuffer[] nativeBuffers,
BufferFormat bufferFormat) {
Platform.runLater(() -> {
videoPixelBuffer.updateBuffer(pb -> null);
});
public void display(MediaPlayer mediaPlayer, ByteBuffer[] nativeBuffers, BufferFormat bufferFormat) {
Platform.runLater(() -> videoPixelBuffer.updateBuffer(pb -> null));
}
}

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close