Skip to content

Commit

Permalink
-Width and height of video from props.
Browse files Browse the repository at this point in the history
-Cleanup
  • Loading branch information
lorenzo-gomez-windhover committed Oct 24, 2024
1 parent e2888a8 commit 068a1ef
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.phoebus.ui.vtype.FormatOption;
import org.phoebus.ui.vtype.FormatOptionHandler;
import uk.co.caprica.vlcj.javafx.videosurface.ImageViewVideoSurface;
import uk.co.caprica.vlcj.player.base.MediaApi;

/**
* Creates JavaFX item for model widget
Expand Down Expand Up @@ -137,13 +136,11 @@ public class CommanderVideoRepresentation
private final UntypedWidgetPropertyListener representationChangedListener =
this::representationChanged;
private final WidgetPropertyListener<Boolean> enablementChangedListener = this::enablementChanged;
private final UntypedWidgetPropertyListener pvsListener = this::pvsChanged;
private final UntypedWidgetPropertyListener pvsListener = this::urlPVUpdate;

private final WidgetPropertyListener<String> pvNameListener = this::pvnameChanged;
private final UntypedWidgetPropertyListener contentListener = this::contentChanged;

private static MediaApi videoMedia;

private static ImageView videoImageView;

private Node mediaPlayerInit(String mediaURL) {
Expand All @@ -168,7 +165,7 @@ private Node mediaPlayerInit(String mediaURL) {
videoImageView.fitWidthProperty().bind(root.widthProperty());
videoImageView.fitHeightProperty().bind(root.heightProperty());

root.setPrefSize(400, 300);
root.setPrefSize(model_widget.propWidth().getValue(), model_widget.propHeight().getValue());

root.widthProperty()
.addListener(
Expand All @@ -182,16 +179,12 @@ private Node mediaPlayerInit(String mediaURL) {
// If you need to know about resizes
});

// videoImageView

root.setCenter(videoImageView);

// embeddedMediaPlayer.media().play("udp://@0.0.0.0:5000");
videoMedia = VideoSingleton.getInstance().getEmbeddedMediaPlayer().media();
updateVideo(mediaURL);

// model_widget.

// model_widget.get

VideoSingleton.getInstance().getEmbeddedMediaPlayer().controls().setPosition(0.4f);

return root;
Expand Down Expand Up @@ -472,7 +465,7 @@ protected void registerListeners() {

// if (! toolkit.isEditMode() && isLabelValue())
//
model_widget.runtimePropValue().addUntypedPropertyListener(representationChangedListener);
model_widget.runtimePropValue().addUntypedPropertyListener(pvsListener);

model_widget.propPVName().addPropertyListener(pvNameListener);

Expand Down Expand Up @@ -529,65 +522,63 @@ private void buttonChanged(
representationChanged(property, old_value, new_value);
}

/**
* Updates video with new URL
*
* @param property
* @param old_value
* @param new_value
*/
private void representationChanged(
public void urlPVUpdate(
final WidgetProperty<?> property, final Object old_value, final Object new_value) {
updateColors();

System.out.println("old value:" + old_value);
System.out.println("new_value:" + new_value);
if (new_value != null) {

String new_value_string =
FormatOptionHandler.format((VType) new_value, FormatOption.STRING, -1, false);

// System.out.println("Val:" + val);
if (old_value != null) {
String old_value_string =
FormatOptionHandler.format((VType) old_value, FormatOption.STRING, -1, false);
if (!old_value_string.equals(new_value_string)) {
// If URL has changed, stream from new URL
System.out.println("New video feed.");
boolean success = updateVideo(new_value_string);
if (success) {
System.out.println("Play returned success");
} else {
System.out.println("Play returned error");
}
} else {
System.out.println("Same old video feed. Do nothing");
}
} else {
//
/**
* We only have a the new video URL. Check videostarted flag. If false, start video at new
* URL
*/
System.out.println("New video feed (if videostarted flag is false)");
String new_value_string =
FormatOptionHandler.format((VType) new_value, FormatOption.STRING, -1, false);

// System.out.println("Val:" + val);
if (old_value != null) {
String old_value_string =
FormatOptionHandler.format((VType) old_value, FormatOption.STRING, -1, false);
if (!old_value_string.equals(new_value_string)) {
// If URL has changed, stream from new URL
System.out.println("New video feed.");
boolean success = updateVideo(new_value_string);
if (success) {
System.out.println("Play returned success");
} else {
System.out.println("Play returned error");
}

// embeddedMediaPlayer.media().info().type()
} else {
System.out.println("Same old video feed. Do nothing");
}
} else {
//
/**
* We only have a the new video URL. Check videostarted flag. If false, start video at new URL
*/
System.out.println("New video feed (if videostarted flag is false)");

boolean success = updateVideo(new_value_string);
if (success) {
System.out.println("Play returned success");
} else {
System.out.println("Play returned error");
}

// embeddedMediaPlayer.media().info().type()
}
}

/**
* Updates video with new URL
*
* @param property
* @param old_value
* @param new_value
*/
private void representationChanged(
final WidgetProperty<?> property, final Object old_value, final Object new_value) {
updateColors();

dirty_representation.mark();
toolkit.scheduleUpdate(this);
}

private boolean updateVideo(String new_value_string) {
return videoMedia.play(new_value_string);
return VideoSingleton.getInstance().getEmbeddedMediaPlayer().media().play(new_value_string);
}

/** Only details of the existing button need to be updated */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import uk.co.caprica.vlcj.player.base.MediaPlayerEventAdapter;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;

/**
* FIXME: The way this is written at the moment it will only allow for one stream at a time. Will
* have to implement an array of of the native objects and essentially manage the alloc/dealloc of
* the objects, will have to be tied to the lifetime of Phoebus unfortunately...
*/
public class VideoSingleton {

private MediaPlayerFactory mediaPlayerFactory;
Expand Down

0 comments on commit 068a1ef

Please sign in to comment.