reproductor multimedia javafx fxml

Does anyone know how to embed a media player in FXML to open a youtube video ?

Yo escribí esto :

<?import javafx....>

<AnchorPane prefHeight="600" VBox.vgrow="ALWAYS">
    <VBox spacing="50" alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <Insets top="30" right="30" bottom="0" left="30"/>
          <MediaPlayer autoPlay="true">
            <Media source="" />

But I am getting this exception in the line where "Media" is declared :

Element does not define a default property.
   at javafx.fxml.FXMLLoader$Element.set(
   at javafx.fxml.FXMLLoader$ValueElement.processEndElement(
   at javafx.fxml.FXMLLoader.processEndElement(
   at javafx.fxml.FXMLLoader.load(
   at javafx.fxml.FXMLLoader.load(
   at javafx.fxml.FXMLLoader$IncludeElement.constructValue(
   at javafx.fxml.FXMLLoader$ValueElement.processStartElement(
   at javafx.fxml.FXMLLoader.processStartElement(
   at javafx.fxml.FXMLLoader.load(
   at javafx.fxml.FXMLLoader.load(
   at javafx.fxml.FXMLLoader.load(
   at javafx.fxml.FXMLLoader.load(
   at javafx.fxml.FXMLLoader.load(
   at javafx.fxml.FXMLLoader.load(
   at javafx.fxml.FXMLLoader.load(

Nadie ?

Gracias a todos !

preguntado el 28 de agosto de 12 a las 11:08

2 Respuestas

AFAIK YouTube doesn't allow to stream his videos for copyright reasons.

1. But you can embed youtube video in WebView in JavaFX:

public class WebViewYouTube extends Application {
    public void start(Stage stage) {
        StackPane root = new StackPane();
        WebView webView = new WebView();

        final WebEngine webEngine = webView.getEngine();
        stage.setScene(new Scene(root, 450, 350));

        webEngine.loadContent("<iframe width='420' height='315' src='' frameborder='0' allowfullscreen></iframe>");;

    public static void main(String[] args) {

2. Same thing with FXML unfortunately requires using Controller as I don't know a way to set content for WebEngine from FXML:

<StackPane xmlns:fx="" fx:controller="fxdemo.SampleController">
    <WebView fx:id="webView"/>

y controlador:

public class SampleController implements Initializable {

    @FXML //  fx:id="webView"
    private WebView webView; // Value injected by FXMLLoader

    @Override // This method is called by the FXMLLoader when initialization is complete
    public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
        webView.getEngine().loadContent("<iframe width='420' height='315' src='' />");


Respondido 28 ago 12, 13:08

Any ideas on how to implement this in FXML? Thanks Sergey ! - Edu Castrillón

Only way I see is one described in the 2nd part of the answer - sergey grinev

For me the 2nd part doesn't work. The project runs but nothing is loaded in the webView. - dyllandria

    I have a class to play video

    @Override public void start(Stage primaryStage) {
        WebView root = new WebView();
          "<video width='640' height='480'controls='controls'>" +
          "<source src=''/>" + 

        primaryStage.setScene(new Scene(root, 660, 500));;`enter code here`

but I need to know if you can linkear an online player, as a transmission of a party or a live event Ej: A transmission or a game of, as I can know what kind of content is and to load it into my webview?

Respondido el 14 de junio de 13 a las 18:06

please translate your text parts into English ... it doesn't need to be perfect ... and users aren't supposed to put you stuff into google translate & co. - alas de kiwi

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.