我陷入了困境我需要从我的数据库中获取视频路径。我不知道怎么把它添加到媒体播放列表上。我用了linkedlist,但似乎不起作用。我需要得到数据库中的所有视频,并在循环播放它们。
将它们添加到播放列表/媒体列表是我的主要问题。我使用的是vlcj1.2.0jar。请帮帮我。
public static void video() throws InterruptedException{
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
Canvas canvas = new Canvas();
canvas.setBackground(Color.black);
CanvasVideoSurface videoSurface = mediaPlayerFactory.newVideoSurface(canvas);
EmbeddedMediaPlayer mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
mediaPlayer.setVideoSurface(videoSurface);
MediaListPlayer mediaListPlayer = mediaPlayerFactory.newMediaListPlayer();
mediaListPlayer.addMediaListPlayerEventListener(new MediaListPlayerEventAdapter() {
@Override
public void nextItem(MediaListPlayer mediaListPlayer, libvlc_media_t item, String itemMrl) {
System.out.println("nextItem()");
}
});
mediaListPlayer.setMediaPlayer(mediaPlayer); // <--- Important, associate the media player with the media list player
vid.add(canvas);
MediaList mediaList = mediaPlayerFactory.newMediaList();
String[] options = {};
LinkedList<String> video = new LinkedList<>();
try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/mediaplaylist";
Connection conn = DriverManager.getConnection(url,"root","");
Statement stmt = conn.createStatement();
String sqlSelect= "select videos from media";
ResultSet rs = stmt.executeQuery(sqlSelect);
while(rs.next()){
String vids= rs.getString("videos");
video.add(vids);
int r= video.size();
for(int s=0; s<r; s++){
mediaList.addMedia(video.get(s), options);
}
mediaListPlayer.setMediaList(mediaList);
mediaListPlayer.setMode(MediaListPlayerMode.LOOP);
mediaListPlayer.play();
}
}catch (Exception ex) {
Logger.getLogger(home.class.getName()).log(Level.SEVERE, null, ex);
}
}
1条答案
按热度按时间r7xajy2e1#
解决了的。这就成功了。
我真傻下面是最后一段代码,我将视频路径保存在mysql数据库中: