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....>
<?import javafx.scene.media.Media?>
<?import javafx.scene.media.MediaPlayer?>
<?import javafx.scene.media.MediaView?>

<AnchorPane prefHeight="600" VBox.vgrow="ALWAYS">
  <children>
    <VBox spacing="50" alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
      <padding>
        <Insets top="30" right="30" bottom="0" left="30"/>
      </padding>
      <children>
        <MediaView>
          <MediaPlayer autoPlay="true">
            <Media source="http://www.youtube.com/watch?v=rCw5JXD18y4" />
          </MediaPlayer>
        </MediaView>
      </children>
    </VBox>
  </children>
</AnchorPane>

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(FXMLLoader.java:142)
   at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:611)
   at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2430)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2136)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
   at javafx.fxml.FXMLLoader$IncludeElement.constructValue(FXMLLoader.java:937)
   at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:567)
   at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2314)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2131)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2742)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2721)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2707)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2694)
   at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2683)
   ...  

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 {
    @Override
    public void start(Stage stage) {
        StackPane root = new StackPane();
        WebView webView = new WebView();

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

        webEngine.loadContent("<iframe width='420' height='315' src='http://www.youtube.com/embed/ZDzVLhjB3bk' frameborder='0' allowfullscreen></iframe>");

        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}

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="http://javafx.com/fxml" fx:controller="fxdemo.SampleController">
  <children>
    <WebView fx:id="webView"/>
  </children>
</StackPane>

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='http://www.youtube.com/embed/ZDzVLhjB3bk' />");
    }

}

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();
        root.getEngine().loadContent(
          "<video width='640' height='480'controls='controls'>" +
          "<source src='http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv'/>" + 
          "</video>");

        primaryStage.setScene(new Scene(root, 660, 500));
        primaryStage.show();`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 justin.tv or a game of www.rojadirecta.mx, as I can know what kind of content is and to load it into my webview?
    Thanks

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.