I'm trying to get play a youtube livestream using JavaFX 8.
package main;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.web.WebView;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
WebView embeddedWV = new WebView();
embeddedWV.getEngine().loadContent(
"<iframe width=\"1280\" height=\"720\" src=\"https://www.youtube.com/embed/5qap5aO4i9A\" "
+ "frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\""
+ " allowfullscreen></iframe>","text/html");
embeddedWV.setPrefSize(640, 400);
root.getChildren().add(embeddedWV);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
The embedded stream loads fine but when I click play, youtube tells me that my "browser" doesn't support any of the video formats. I tried with webview and with mediaplayer, but I can't even get the page to load in mediaplayer.