javaFx使用vlc播放器播放流媒体

vlc是一个很不错的视频播放器

下载地址 https://www.videolan.org/

如何测试流媒体链接?

javaFx使用vlc播放器播放流媒体_第1张图片

javaFx使用vlc播放器播放流媒体_第2张图片

如何在javaFx项目中集成vlc播放器?

https://github.com/caprica

1、导入依赖jar

    <dependency>
            <groupId>uk.co.caprica</groupId>
            <artifactId>vlcj-javafx</artifactId>
            <version>1.0.2</version>
    </dependency>
    
2、撸码
public class PrimaryController implements Initializable {

    private MediaPlayerFactory mediaPlayerFactory;
    private EmbeddedMediaPlayer embeddedMediaPlayer;

    @FXML
    private ImageView imageView;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {


        mediaPlayerFactory = new MediaPlayerFactory();
        embeddedMediaPlayer = mediaPlayerFactory.mediaPlayers().newEmbeddedMediaPlayer();
        imageView.setPreserveRatio(true);
        embeddedMediaPlayer.videoSurface().set(ImageViewVideoSurfaceFactory.videoSurfaceForImageView(imageView));
        this.embeddedMediaPlayer.events().addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
            @Override
            public void playing(MediaPlayer mediaPlayer) {
            }

            @Override
            public void paused(MediaPlayer mediaPlayer) {
            }

            @Override
            public void stopped(MediaPlayer mediaPlayer) {
            }

            @Override
            public void timeChanged(MediaPlayer mediaPlayer, long newTime) {
            }
        });

    }

    @FXML
    public void stop() {
        embeddedMediaPlayer.controls().stop();
        embeddedMediaPlayer.release();
        mediaPlayerFactory.release();
    }

    @FXML
    public void play() {
        embeddedMediaPlayer.controls().setPosition(0.4f);
        embeddedMediaPlayer.media().play("rtsp://192.168.5.30:8086");
    }
}

3、完

其他平台如何集成

https://github.com/videolan

你可能感兴趣的:(javafx,vlc,vlc播放器,流媒体,vlc集成)