简体   繁体   中英

JavaFX MediaView in FXML

I have tried to create a MediaView in my fxml but it does not seem to work and just brings up errors. The video I am playing is based locally.

<MediaView>
   <MediaPlayer>
      <Media source="vid/video.avi"/>
   </MediaPlayer>
</MediaView>

With your FXML code, I get this warnings:

Class javafx.scene.media.MediaView has no default property. Place javafx.scene.media.MediaView content in a proper element.

Class javafx.scene.media.MediaPlayer has no default property. Place javafx.scene.media.MediaPlayer content in a proper element.

If you edit your FXML file on NetBeans, when you start adding <MediaView> , click Ctrl+space, and from all the properties, select mediaPlayer . Then Ctrl+space again, and select MediaPlayer . Now add media , and finally Media .

This is how it should look like:

<AnchorPane prefHeight="480.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
    <children>
        <MediaView >
            <mediaPlayer>
                <MediaPlayer autoPlay="true">
                    <media>
                        <Media source="http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv" />
                    </media>
                </MediaPlayer>
            </mediaPlayer>    
        </MediaView>
    </children>
</AnchorPane>

Note that mediaPlayer is a property of MediaView :

private ObjectProperty<MediaPlayer> mediaPlayer;

while media is a named argument of MediaPlayer :

public MediaPlayer(@NamedArg("media") Media media)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM