Java利用vlc实现视频信息输出控制台

1、废话不多说直接上代码,项目配置去找上篇博客

分享一波源码地址:https://github.com/caprica/vlcj

package test;



import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;

import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.player.MediaPlayer;
import uk.co.caprica.vlcj.player.MediaPlayerEventAdapter;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.TrackType;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
/**
 * 所属包:test
* 类名:TheMedia
* -------------------
* 描述:采集本地视频信息
* -------------------
* 日期:2018年11月21日
* 作者:cuixin */ public class TheMedia { private static final String NATIVE_LIBRARY_SEARCH_PATH = "F://VLC"; private final static String mrl = "F:\\网易云下载目录\\MV\\2.mp4"; public static void main(String[] args) throws Exception { NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), NATIVE_LIBRARY_SEARCH_PATH); Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class); boolean discover = new NativeDiscovery().discover(); MediaPlayerFactory factory = new MediaPlayerFactory(); MediaPlayer mediaPlayer = factory.newHeadlessMediaPlayer(); mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() { @Override public void videoOutput(MediaPlayer mediaPlayer, int newCount) { System.out.println("跟踪信息:" + mediaPlayer.getTrackInfo()); //System.out.println("标题描述: " + mediaPlayer.getTitleDescriptions()); System.out.println("视频描述: " + mediaPlayer.getVideoDescriptions()); System.out.println("音频描述: " + mediaPlayer.getAudioDescriptions()); for(int i = 0; i < mediaPlayer.getTitleDescriptions().size(); i ++ ) { System.out.println("章节描述:" + i + ": " + mediaPlayer.getChapterDescriptions(i)); } //System.out.println("扩展标题: " + mediaPlayer.getExtendedTitleDescriptions()); //System.out.println("扩展章节: " + mediaPlayer.getExtendedChapterDescriptions()); } }); mediaPlayer.prepareMedia(mrl); mediaPlayer.parseMedia(); try { Thread.sleep(3000); } catch(InterruptedException e) { } System.out.println("跟踪结束之前的信息: " + mediaPlayer.getTrackInfo()); //System.out.println("未知的: " + mediaPlayer.getTrackInfo(TrackType.UNKNOWN)); System.out.println("音频信息: " + mediaPlayer.getTrackInfo(TrackType.AUDIO)); System.out.println("视频信息: " + mediaPlayer.getTrackInfo(TrackType.VIDEO)); //System.out.println("文本信息: " + mediaPlayer.getTrackInfo(TrackType.TEXT)); System.out.println("音频+视频: " + mediaPlayer.getTrackInfo(TrackType.AUDIO, TrackType.VIDEO)); mediaPlayer.stop(); mediaPlayer.release(); factory.release(); } }

 

你可能感兴趣的:(vlc)