-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
040f07f
commit 4170df7
Showing
7 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dependencies { | ||
implementation "com.sandec.jpro:jpro-webapi:$JPRO_VERSION" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
plugins { | ||
id 'org.openjfx.javafxplugin' | ||
id 'jpro-gradle-plugin' | ||
} | ||
|
||
mainClassName = "one.jpro.platform.youtube.example.YoutubeExample" | ||
|
||
application { | ||
mainClass = "$mainClassName" | ||
mainModule = moduleName | ||
} | ||
|
||
dependencies { | ||
implementation project(':jpro-youtube') | ||
} | ||
|
||
javafx { | ||
version = "$JAVAFX_VERSION" | ||
modules = ['javafx.graphics', 'javafx.controls', 'javafx.swing', 'javafx.fxml', 'javafx.media', 'javafx.web'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module one.jpro.platform.youtube.example { | ||
requires one.jpro.platform.youtube; | ||
requires javafx.controls; | ||
requires jpro.webapi; | ||
|
||
exports one.jpro.platform.youtube.example; | ||
} |
24 changes: 24 additions & 0 deletions
24
jpro-youtube/example/src/main/java/one/jpro/platform/youtube/example/YoutubeExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package one.jpro.platform.youtube.example; | ||
|
||
import javafx.application.Application; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.layout.StackPane; | ||
import javafx.scene.layout.VBox; | ||
import one.jpro.platform.youtube.YoutubeNode; | ||
import org.scenicview.ScenicView; | ||
|
||
public class YoutubeExample extends Application { | ||
|
||
@Override | ||
public void start(javafx.stage.Stage stage) throws Exception { | ||
var pin = new VBox(); | ||
|
||
pin.getChildren().add(new StackPane(new YoutubeNode("dQw4w9WgXcQ"))); | ||
pin.getChildren().add(new StackPane(new YoutubeNode("oqAsIcoN9MY"))); | ||
stage.setScene(new javafx.scene.Scene(new VBox(pin))); | ||
|
||
ScenicView.show(stage.getScene()); | ||
|
||
stage.show(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module one.jpro.platform.youtube { | ||
|
||
requires jpro.webapi; | ||
requires javafx.graphics; | ||
requires javafx.web; | ||
exports one.jpro.platform.youtube; | ||
} |
73 changes: 73 additions & 0 deletions
73
jpro-youtube/src/main/java/one/jpro/platform/youtube/YoutubeNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package one.jpro.platform.youtube; | ||
|
||
import com.jpro.webapi.HTMLView; | ||
import javafx.geometry.Orientation; | ||
import javafx.scene.layout.Region; | ||
import javafx.scene.layout.StackPane; | ||
import com.jpro.webapi.WebAPI; | ||
import javafx.scene.web.WebView; | ||
|
||
/** | ||
* A Node that displays a Youtube Video. | ||
*/ | ||
public class YoutubeNode extends StackPane { | ||
|
||
protected int PREF_HEIGHT = 340; | ||
protected int PREF_WIDTH = 560; | ||
|
||
protected double ratio = 16.0/9.0; | ||
|
||
/** | ||
* Creates a new YoutubeNode with the given videoId. | ||
* @param videoId the id of the video to display | ||
*/ | ||
public YoutubeNode(String videoId) { | ||
|
||
setPrefSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE); | ||
setMinSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE); | ||
setMaxSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE); | ||
//setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE); | ||
|
||
if(WebAPI.isBrowser()) { | ||
var htmlView = new HTMLView(); | ||
htmlView.setContent("<iframe src=\"https://www.youtube.com/embed/"+videoId+"\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>"); | ||
getChildren().add(htmlView); | ||
WebAPI.getWebAPI(this, webAPI -> { | ||
var elem = webAPI.getHTMLViewElement(htmlView); | ||
widthProperty().addListener((observable, oldValue, newValue) -> { | ||
webAPI.executeScript(elem.getName()+".firstElementChild.width = "+newValue.intValue()+";"); | ||
}); | ||
heightProperty().addListener((observable, oldValue, newValue) -> { | ||
webAPI.executeScript(elem.getName()+".firstElementChild.height = "+newValue.intValue()+";"); | ||
}); | ||
webAPI.executeScript(elem.getName()+".firstElementChild.width = "+getWidth()+";"); | ||
webAPI.executeScript(elem.getName()+".firstElementChild.height = "+getHeight()+";"); | ||
}); | ||
} else { | ||
var webView = new WebView(); | ||
webView.getEngine().load("https://www.youtube.com/embed/"+videoId); | ||
getChildren().add(webView); | ||
} | ||
} | ||
|
||
@Override | ||
public Orientation getContentBias() { | ||
return Orientation.HORIZONTAL; | ||
} | ||
|
||
@Override | ||
protected double computePrefWidth(double height) { | ||
if(height <= -1) { | ||
return PREF_WIDTH; | ||
} | ||
return height * ratio; | ||
} | ||
|
||
@Override | ||
protected double computePrefHeight(double width) { | ||
if(width <= -1) { | ||
return PREF_HEIGHT; | ||
} | ||
return width / ratio; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters