Skip to content

Commit

Permalink
Mirror error handling of audio for video player
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Aug 12, 2023
1 parent 67643ee commit 64626c8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ public class ByteHeaderUtil {
M4ADash);
// Video
// For MP4/QuickTime see: https://www.ftyps.com/
// JavaFX does not support MOV/MKV
public static final int[] MP4_FYTP_MMP4 = {WILD, WILD, WILD, WILD, 0x66, 0x74, 0x79, 0x70, 0x6D, 0x6D, 0x70, 0x34};
public static final int[] MP4_FYTP_MP42 = {WILD, WILD, WILD, WILD, 0x66, 0x74, 0x79, 0x70, 0x6D, 0x70, 0x34, 0x32};
public static final int[] MP4_FTYP = {WILD, WILD, WILD, WILD, 0x66, 0x74, 0x79, 0x70};
public static final int[] MKV = {0x1A, 0x45, 0xDF, 0xA3, 0xA3, 0x42, 0x86, 0x81, 0x01, 0x42, 0xF7, 0x81};
public static final List<int[]> VIDEO_HEADERS = List.of(
MP4_FYTP_MMP4,
MP4_FYTP_MP42
MP4_FTYP,
MKV
);
// Android files (Modular chunk system, use unsigned short LE headers)
public static final int[] BINARY_XML = {0x03, 0x00};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import software.coley.recaf.ui.control.FontIconView;
import software.coley.recaf.ui.control.ImageCanvas;
import software.coley.recaf.ui.control.PannableView;
import software.coley.recaf.util.Animations;

import java.io.ByteArrayInputStream;
import java.util.Collection;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void onUpdatePath(@Nonnull PathNode<?> path) {
*/
private class ColorAdjustmentControls extends Group {
private ColorAdjustmentControls() {
setupShowOnHover();
Animations.setupShowOnHover(this);

GridPane box = new GridPane();
box.setAlignment(Pos.CENTER);
Expand All @@ -103,26 +104,5 @@ private ColorAdjustmentControls() {

getChildren().add(box);
}

private void setupShowOnHover() {
double hiddenOpacity = 0.1;
DoubleProperty opacity = opacityProperty();
opacity.set(hiddenOpacity);

FadeTransition show = new FadeTransition(Duration.millis(250), this);
show.setToValue(1.0);

FadeTransition hide = new FadeTransition(Duration.millis(250), this);
hide.setToValue(hiddenOpacity);

setOnMouseEntered(e -> {
show.setFromValue(opacity.doubleValue());
show.play();
});
setOnMouseExited(e -> {
hide.setFromValue(opacity.doubleValue());
hide.play();
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package software.coley.recaf.ui.pane.editing.media;

import atlantafx.base.theme.Styles;
import jakarta.annotation.Nonnull;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
Expand Down Expand Up @@ -47,8 +48,9 @@ protected Region interactionBar() {
btnPlay.setGraphic(Icons.getIconView(Icons.PLAY));
btnPause.setGraphic(Icons.getIconView(Icons.PAUSE));
btnStop.setGraphic(Icons.getIconView(Icons.STOP));
btnPlay.getStyleClass().add("rounded-button-left");
btnStop.getStyleClass().add("rounded-button-right");
btnPlay.getStyleClass().add(Styles.LEFT_PILL);
btnPause.getStyleClass().add(Styles.CENTER_PILL);
btnStop.getStyleClass().add(Styles.RIGHT_PILL);
btnPlay.setOnAction(e -> {
getPlayer().play();
btnPlay.setDisable(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import jakarta.annotation.Nonnull;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
import javafx.scene.control.Label;
import javafx.scene.media.MediaView;
import software.coley.recaf.info.FileInfo;
import software.coley.recaf.path.FilePathNode;
import software.coley.recaf.path.PathNode;
import software.coley.recaf.ui.media.FxPlayer;
import software.coley.recaf.ui.media.Player;
import software.coley.recaf.util.FxThreadUtil;

import java.io.IOException;

Expand Down Expand Up @@ -38,11 +40,18 @@ public void onUpdatePath(@Nonnull PathNode<?> path) {
view.setPreserveRatio(true);
view.fitHeightProperty().bind(heightProperty().subtract(40));
} catch (IOException ex) {
logger.warn("Could not load video from '{}'", fileInfo.getName(), ex);
onLoadFailure(fileInfo, ex);
}
}
}

private void onLoadFailure(@Nonnull FileInfo fileInfo, @Nonnull IOException ex) {
logger.warn("Could not load video from '{}'", fileInfo.getName(), ex);
FxThreadUtil.delayedRun(100, () -> {
setCenter(new Label(ex.getMessage()));
});
}

@Override
protected Player getPlayer() {
return player;
Expand Down
29 changes: 29 additions & 0 deletions recaf-ui/src/main/java/software/coley/recaf/util/Animations.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package software.coley.recaf.util;

import jakarta.annotation.Nonnull;
import javafx.animation.FadeTransition;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
Expand Down Expand Up @@ -81,4 +83,31 @@ private static void animate(Node node, long millis, int r, int g, int b) {
timeline.getKeyFrames().add(kf);
timeline.play();
}

/**
* Registers mouse-enter/exit events which transition the opacity of the given node.
*
* @param node
* Not to install show-on-hover.
*/
public static void setupShowOnHover(@Nonnull Node node) {
double hiddenOpacity = 0.1;
DoubleProperty opacity = node.opacityProperty();
opacity.set(hiddenOpacity);

FadeTransition show = new FadeTransition(Duration.millis(250), node);
show.setToValue(1.0);

FadeTransition hide = new FadeTransition(Duration.millis(250), node);
hide.setToValue(hiddenOpacity);

node.setOnMouseEntered(e -> {
show.setFromValue(opacity.doubleValue());
show.play();
});
node.setOnMouseExited(e -> {
hide.setFromValue(opacity.doubleValue());
hide.play();
});
}
}

0 comments on commit 64626c8

Please sign in to comment.