javaFx使用vlc播放器播放流媒体
程序员文章站
2022-07-07 14:01:34
...
vlc是一个很不错的视频播放器
下载地址 https://www.videolan.org/
如何测试流媒体链接?
如何在javaFx项目中集成vlc播放器?
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");
}
}