live video streaming from url in javafx - javafx

I want to show live streaming video from url in javafx. I am using webview.
It is showing only text in that webpage. It is not showing live video streaming. Please suggest me a way to do that.
public class A extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
WebView webView = new WebView();
webView.getEngine().load("http://192.168.0.143:8000/");
VBox vbox = new VBox(webView);
Scene scene = new Scene(vbox);
stage.setScene(scene);
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}

Related

JavaFX WebEngine is not tracked in blog statistics of wordpress

I have notice that a visit from a JavaFx WebEngine is not tracked in the statistics of the website/blog.
Thats the code i use. The website is loaded but if I check my statistics in the wordpress-administration-tool, there is not any visit tracked.
public class Example extends Application {
#Override
public void start(Stage stage) throws Exception {
BorderPane borderPane = new BorderPane();
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
borderPane.setCenter(browser);
webEngine.load("https://somewordpressblog.wordpress.com/");
Scene scene = new Scene(borderPane, 400, 300);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Does anyone know why?

How can i create a stage in java FX which forces user to first close it for doing anything else?

I am creating a desktop app using java fx and here I want to prevent the user from accessing the PC unless my app is closed.
I tried using showAndWait() function but it is not applicable to primary stage.
Its a single page app.
Help will be appreciated. Thanks!
Here is my main class and i am using scene builder for designing.
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
TilePane root = FXMLLoader.load(getClass().getResource("/application/Layout.fxml"));
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.showAndWait();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}

Switching scenes in JavaFX(FXML) error

So, I'm trying to switch scenes in JavaFX but I can't seem to get it to work when I hard coded it I was able to get it working by using lambda expressions.
public class Main extends Application {
Stage window;
Scene scene1;
Scene scene2;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
Label label = new Label("Welcome to the first scene");
Button bttn1 = new Button("Go to second scene");
bttn1.setOnAction(e -> window.setScene(scene2));
//Scene 1
VBox layout1 = new VBox(20);
layout1.getChildren().addAll(label, bttn1);
scene1 = new Scene(layout1, 400, 400);
//Scene 2
Button bttn2 = new Button("Go to first scene");
bttn2.setOnAction(e -> window.setScene(scene1));
StackPane layout2 = new StackPane();
layout2.getChildren().add(bttn2);
scene2 = new Scene(layout2, 400, 500);
window.setScene(scene1);
window.setTitle("Test");
window.show();
}
However the project involves a few different GUIs and I would prefer to design the GUI's in FXML Scene Builder than to hardcode them the FX way. However when I have tried to do the FXML way it hasn't worked an error is always appearing when I press the button.
Error message
This is the document controller code.
public class FXMLDocumentController implements Initializable {
#FXML
private Button button1;
#FXML
private Button button2;
#FXML
private void handleButtonAction(ActionEvent event) throws IOException {
Stage stage;
Parent root;
if(event.getSource() == button1){
stage=(Stage)button1.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("FXML2.fxml"));
}
else{
stage=(Stage)button2.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
}
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
The error you posted says the code is trying to load a button as an anchor pane. Check too see if you have an anchorpane with the fx:I'd of button1.

action on a Video Tag webview, Javafx

I work on a javafx project. I have this code.
public class MoviePlayer extends Application{
public static void main(String[] args)
{
launch(args);
}
#Override
public void start(Stage stage) throws Exception
{
WebView root = new WebView();
root.getEngine().loadContent(
"<video width='320' height='240'controls='controls' >" +
"<source src='file:///C:/Users/lenovo-pc/workspace/EnhanceVideoJava/Movie_0001_512kb.mp4'/>" +
"Your browser does not support the video tag." +
"</video> ");
stage.setScene(new Scene(root, 500, 400));
stage.show();
}}
Now, I want to create an action when i click on the video. Is it possible??
Tanks

Full Screen JavaFX Anchor Pane with title bar

I want to set full screen Anchor Pane with title Bar in JavaFX. I used the property
stage.setFullScreen(true);
but it does not show title bar. What should I do to make my Anchor Pane full screen but with title bar?
After using setMaximized(true); clean and build your project.
public class Test extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("DashBoard.fxml"));
stage.getIcons().add(new Image("/com/images/icon.png"));
Scene scene = new Scene(root);
stage.setTitle("Dash Board");
stage.setMaximized(true);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}

Resources