下面列出了android.view.View.OnSystemUiVisibilityChangeListener#org.videolan.libvlc.LibVLC 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public VLCSampleExtractor(LibVLC vlc, String uri) throws ExoPlaybackException {
if (vlc == null || uri == null)
throw new ExoPlaybackException("null parms!");
this.uri = uri;
this.lib = vlc;
this.media = ExoVlcUtil.getMedia(vlc, uri);
this.vlctracks = ExoVlcUtil.getAvailableTracks(media);
if (this.vlctracks.length > 0)
this.trackInfos = ExoVlcUtil.vlc2exoTracks(media.getDuration(), vlctracks, lib);
else
try {
if ((hasVdo = vlc.hasVideoTrack(uri)))
this.trackInfos = ExoVlcUtil.getDummyVdoTrack(media,
com.exovlc.ExoVlcUtil.DUMM_VDO_MIME);
} catch (IOException e1) {
e1.printStackTrace();
}
ExoVlcUtil.log(this, "get vlc tracks for uri = " + uri);
}
/**
*
* @param media
* @param vlcTracks
* @param lib
* @return
*/
static com.google.android.exoplayer.TrackInfo[] vlc2exoTracks(long duration,
org.videolan.libvlc.Media.Track[] vlcTracks, LibVLC lib) {
com.google.android.exoplayer.TrackInfo[] res = new com.google.android.exoplayer.TrackInfo[vlcTracks.length];
System.out.println("ExoVlcUtil.vlc2exoTracks() vlcTracks = " + vlcTracks.length);
// Media.Track
for (int i = 0; i < res.length; i++) {
MediaFormat mf = track2mediaFormat(vlcTracks[i]);
res[i] = new TrackInfo(mf.getString(MediaFormat.KEY_MIME), duration);
System.out.println("\t track " + i + " mime type =" + mf.getString(MediaFormat.KEY_MIME) + " duration ="
+ duration);
}
/*
* System.out.println(">>>> ExoVlcUtil.vlc2exoTracks() vlcTracks.length = "
* +vlcTracks.length); long l; for (int i = 0; i < vlcTracks.length;
* i++) { org.videolan.libvlc.TrackInfo vt = vlcTracks[i];
* System.out.println("\t\t >>>>>Codec("+i+") "+vlcTracks[i].Codec);
* res[i] = new TrackInfo( vt.Codec, (l=lib.getLength()) == -1 ?
* com.google.android.exoplayer.C.UNKNOWN_TIME_US : l * MS_2_MICRO); }
*/
return res;
}
public VLCVideoSurfaceHandler( LibVLC libvlc, Handler eventHandler,
MediaCodecVideoTrackRenderer.EventListener eventListener, SurfaceLayoutHandler layoutHandler) throws ExoPlaybackException {
super();
this.libvlc = libvlc;
this.eventHandler = eventHandler;
this.eventListener = eventListener;
if (layoutHandler != null) {
this.layoutHandler = layoutHandler;
SurfaceHolder surfaceHolder = layoutHandler.getHolder();
ExoVlcUtil.log(this, "VLCIVideoSurfaceHandler.VLCIVideoSurfaceHandler()");
ExoVlcUtil.log(this, "## ====> rect= " + surfaceHolder.getSurfaceFrame());
if (com.exovlc.ExoVlcUtil.validSurface(surfaceHolder))
setVlcSurface(surfaceHolder.getSurface(), false);
} else
throw new ExoPlaybackException("layout handler null.");
}
public VLCSampleExtractor(LibVLC vlc, String uri) throws ExoPlaybackException {
if (vlc == null || uri == null)
throw new ExoPlaybackException("null parms!");
this.uri = uri;
this.lib = vlc;
this.media = ExoVlcUtil.getMedia(vlc, uri);
this.vlctracks = ExoVlcUtil.getAvailableTracks(media);
if (this.vlctracks.length > 0)
this.trackInfos = ExoVlcUtil.vlc2exoTracks(media.getDuration(), vlctracks, lib);
else
try {
if ((hasVdo = vlc.hasVideoTrack(uri)))
this.trackInfos = ExoVlcUtil.getDummyVdoTrack(media,
com.exovlc.ExoVlcUtil.DUMM_VDO_MIME);
} catch (IOException e1) {
e1.printStackTrace();
}
ExoVlcUtil.log(this, "get vlc tracks for uri = " + uri);
}
/**
*
* @param media
* @param vlcTracks
* @param lib
* @return
*/
static com.google.android.exoplayer.TrackInfo[] vlc2exoTracks(long duration,
org.videolan.libvlc.Media.Track[] vlcTracks, LibVLC lib) {
com.google.android.exoplayer.TrackInfo[] res = new com.google.android.exoplayer.TrackInfo[vlcTracks.length];
System.out.println("ExoVlcUtil.vlc2exoTracks() vlcTracks = " + vlcTracks.length);
// Media.Track
for (int i = 0; i < res.length; i++) {
MediaFormat mf = track2mediaFormat(vlcTracks[i]);
res[i] = new TrackInfo(mf.getString(MediaFormat.KEY_MIME), duration);
System.out.println("\t track " + i + " mime type =" + mf.getString(MediaFormat.KEY_MIME) + " duration ="
+ duration);
}
/*
* System.out.println(">>>> ExoVlcUtil.vlc2exoTracks() vlcTracks.length = "
* +vlcTracks.length); long l; for (int i = 0; i < vlcTracks.length;
* i++) { org.videolan.libvlc.TrackInfo vt = vlcTracks[i];
* System.out.println("\t\t >>>>>Codec("+i+") "+vlcTracks[i].Codec);
* res[i] = new TrackInfo( vt.Codec, (l=lib.getLength()) == -1 ?
* com.google.android.exoplayer.C.UNKNOWN_TIME_US : l * MS_2_MICRO); }
*/
return res;
}
public VLCVideoSurfaceHandler( LibVLC libvlc, Handler eventHandler,
MediaCodecVideoTrackRenderer.EventListener eventListener, SurfaceLayoutHandler layoutHandler) throws ExoPlaybackException {
super();
this.libvlc = libvlc;
this.eventHandler = eventHandler;
this.eventListener = eventListener;
if (layoutHandler != null) {
this.layoutHandler = layoutHandler;
SurfaceHolder surfaceHolder = layoutHandler.getHolder();
ExoVlcUtil.log(this, "VLCIVideoSurfaceHandler.VLCIVideoSurfaceHandler()");
ExoVlcUtil.log(this, "## ====> rect= " + surfaceHolder.getSurfaceFrame());
if (com.exovlc.ExoVlcUtil.validSurface(surfaceHolder))
setVlcSurface(surfaceHolder.getSurface(), false);
} else
throw new ExoPlaybackException("layout handler null.");
}
/**
* Get a media thumbnail.
* @return a bytearray with the RGBA thumbnail data inside.
*/
public static byte[] getThumbnail(LibVLC libVLC, Uri uri, int i_width, int i_height) {
/* dvd thumbnails can work only with dvdsimple demux */
if (uri.getLastPathSegment().endsWith(".iso"))
uri = Uri.parse("dvdsimple://" + uri.getEncodedPath());
final Media media = new Media(libVLC, uri);
byte[] bytes = getThumbnail(media, i_width, i_height);
media.release();
return bytes;
}
/**
* Create a Dumper that will download an Uri into a local filesystem path
* @param uri the Uri to dump
* @param filepath local filesystem path where to dump the Uri
* @param listener listener in order to be notified when the dump is finished
*/
@MainThread
public Dumper(Uri uri, String filepath, Listener listener) {
if (uri == null || filepath == null || listener == null)
throw new IllegalArgumentException("arguments shouldn't be null");
mListener = listener;
ArrayList<String> options = new ArrayList<>(8);
options.add("--demux");
options.add("dump2,none");
options.add("--demuxdump-file");
options.add(filepath);
options.add("--no-video");
options.add("--no-audio");
options.add("--no-spu");
options.add("-vv");
mLibVLC = new LibVLC(null, options);
final Media media = new Media(mLibVLC, uri);
mMediaPlayer = new MediaPlayer(media);
mMediaPlayer.setEventListener(new MediaPlayer.EventListener() {
@Override
public void onEvent(MediaPlayer.Event event) {
switch (event.type) {
case MediaPlayer.Event.Buffering:
mListener.onProgress(event.getBuffering());
break;
case MediaPlayer.Event.EncounteredError:
case MediaPlayer.Event.EndReached:
mListener.onFinish(event.type == MediaPlayer.Event.EndReached);
cancel();
break;
}
}
});
media.release();
}
/**
* Get a media thumbnail.
* @return a bytearray with the RGBA thumbnail data inside.
*/
public static byte[] getThumbnail(LibVLC libVLC, Uri uri, int i_width, int i_height) {
/* dvd thumbnails can work only with dvdsimple demux */
if (uri.getLastPathSegment().endsWith(".iso"))
uri = Uri.parse("dvdsimple://" + uri.getEncodedPath());
final Media media = new Media(libVLC, uri);
byte[] bytes = getThumbnail(media, i_width, i_height);
media.release();
return bytes;
}
VLCTrackRenderer(VLCSampleSource source, Handler eventHandler, MediaCodecTrackRenderer.EventListener eventListener,
LibVLC vlc) {
if (vlc == null)
throw new NullPointerException("null vlc parm if prohibited");
this.vlc = vlc;
this.source = source;
this.eventHandler = eventHandler;
this.eventListener = eventListener;
}
/**
* Get a media thumbnail.
* @return a bytearray with the RGBA thumbnail data inside.
*/
public static byte[] getThumbnail(LibVLC libVLC, Uri uri, int i_width, int i_height) {
/* dvd thumbnails can work only with dvdsimple demux */
if (uri.getLastPathSegment().endsWith(".iso"))
uri = Uri.parse("dvdsimple://" + uri.getEncodedPath());
final Media media = new Media(libVLC, uri);
byte[] bytes = getThumbnail(media, i_width, i_height);
media.release();
return bytes;
}
/**
* Create a Dumper that will download an Uri into a local filesystem path
* @param uri the Uri to dump
* @param filepath local filesystem path where to dump the Uri
* @param listener listener in order to be notified when the dump is finished
*/
@MainThread
public Dumper(Uri uri, String filepath, Listener listener) {
if (uri == null || filepath == null || listener == null)
throw new IllegalArgumentException("arguments shouldn't be null");
mListener = listener;
ArrayList<String> options = new ArrayList<>(8);
options.add("--demux");
options.add("dump2,none");
options.add("--demuxdump-file");
options.add(filepath);
options.add("--no-video");
options.add("--no-audio");
options.add("--no-spu");
options.add("-vv");
mLibVLC = new LibVLC(null, options);
final Media media = new Media(mLibVLC, uri);
mMediaPlayer = new MediaPlayer(media);
mMediaPlayer.setEventListener(new MediaPlayer.EventListener() {
@Override
public void onEvent(MediaPlayer.Event event) {
switch (event.type) {
case MediaPlayer.Event.Buffering:
mListener.onProgress(event.getBuffering());
break;
case MediaPlayer.Event.EncounteredError:
case MediaPlayer.Event.EndReached:
mListener.onFinish(event.type == MediaPlayer.Event.EndReached);
cancel();
break;
}
}
});
media.release();
}
/**
* Get a media thumbnail.
* @return a bytearray with the RGBA thumbnail data inside.
*/
public static byte[] getThumbnail(LibVLC libVLC, Uri uri, int i_width, int i_height) {
/* dvd thumbnails can work only with dvdsimple demux */
if (uri.getLastPathSegment().endsWith(".iso"))
uri = Uri.parse("dvdsimple://" + uri.getEncodedPath());
final Media media = new Media(libVLC, uri);
byte[] bytes = getThumbnail(media, i_width, i_height);
media.release();
return bytes;
}
/**
* Create a Dumper that will download an Uri into a local filesystem path
* @param uri the Uri to dump
* @param filepath local filesystem path where to dump the Uri
* @param listener listener in order to be notified when the dump is finished
*/
@MainThread
public Dumper(Uri uri, String filepath, Listener listener) {
if (uri == null || filepath == null || listener == null)
throw new IllegalArgumentException("arguments shouldn't be null");
mListener = listener;
ArrayList<String> options = new ArrayList<>(8);
options.add("--demux");
options.add("dump2,none");
options.add("--demuxdump-file");
options.add(filepath);
options.add("--no-video");
options.add("--no-audio");
options.add("--no-spu");
options.add("-vv");
mLibVLC = new LibVLC(null, options);
final Media media = new Media(mLibVLC, uri);
mMediaPlayer = new MediaPlayer(media);
mMediaPlayer.setEventListener(new MediaPlayer.EventListener() {
@Override
public void onEvent(MediaPlayer.Event event) {
switch (event.type) {
case MediaPlayer.Event.Buffering:
mListener.onProgress(event.getBuffering());
break;
case MediaPlayer.Event.EncounteredError:
case MediaPlayer.Event.EndReached:
mListener.onFinish(event.type == MediaPlayer.Event.EndReached);
cancel();
break;
}
}
});
media.release();
}
public VlcVideoLibrary(Context context, VlcListener vlcListener, Surface surface) {
this.vlcListener = vlcListener;
this.surface = surface;
surfaceHolder = null;
vlcInstance = new LibVLC(context, new VlcOptions().getDefaultOptions());
options.add(":fullscreen");
}
public VlcVideoLibrary(Context context, VlcListener vlcListener, Surface surface,
SurfaceHolder surfaceHolder) {
this.vlcListener = vlcListener;
this.surface = surface;
this.surfaceHolder = surfaceHolder;
vlcInstance = new LibVLC(context, new VlcOptions().getDefaultOptions());
options.add(":fullscreen");
}
public VlcVideoLibrary(Context context, VlcListener vlcListener, Surface surface, int width,
int height) {
this.vlcListener = vlcListener;
this.surface = surface;
this.width = width;
this.height = height;
surfaceHolder = null;
vlcInstance = new LibVLC(context, new VlcOptions().getDefaultOptions());
options.add(":fullscreen");
}
public VlcVideoLibrary(Context context, VlcListener vlcListener, Surface surface,
SurfaceHolder surfaceHolder, int width, int height) {
this.vlcListener = vlcListener;
this.surface = surface;
this.surfaceHolder = surfaceHolder;
this.width = width;
this.height = height;
vlcInstance = new LibVLC(context, new VlcOptions().getDefaultOptions());
options.add(":fullscreen");
}
private void createPlayer() {
releasePlayer();
String videoLink = UniversalPlayer.getInstance().getPlayingMediaItem().getAudeoLink();
try {
Logger.printInfo(TAG, "Trying to play video: " + videoLink);
ArrayList<String> options = new ArrayList<String>();
options.add("--aout=opensles");
options.add("--audio-time-stretch"); // time stretching
options.add("-vvv"); // verbosity
libvlc = new LibVLC(options);
shVideoHolder.setKeepScreenOn(true);
// Create media player
mMediaPlayer = new MediaPlayer(libvlc);
mMediaPlayer.setEventListener(this);
// Set up video output
final IVLCVout vout = mMediaPlayer.getVLCVout();
vout.setVideoView(sfVideo);
vout.addCallback(this);
vout.attachViews();
Media m = URLUtil.isValidUrl(videoLink) ? new Media(libvlc, Uri.parse(videoLink)) : new Media(libvlc, videoLink);
mMediaPlayer.setMedia(m);
mMediaPlayer.play();
} catch (Exception e) {
Logger.printInfo(TAG, "Error creating video player: ");
e.printStackTrace();
if (onPlayingFailedCallback != null) {
onPlayingFailedCallback.operationFinished();
}
}
}
/**
* @param libvlc The LibVLC instance to use
* @param listener The Listener which will receive callbacks
* <p>
* With this constructor, callbacks will be executed in the main thread
*/
public MediaBrowser(LibVLC libvlc, EventListener listener) {
mLibVlc = libvlc;
mLibVlc.retain();
mEventListener = listener;
mAlive = true;
}
/**
* Get a media thumbnail.
*
* @return a bytearray with the RGBA thumbnail data inside.
*/
public static byte[] getThumbnail(LibVLC libVLC, Uri uri, int i_width, int i_height) {
/* dvd thumbnails can work only with dvdsimple demux */
if (uri.getLastPathSegment().endsWith(".iso"))
uri = Uri.parse("dvdsimple://" + uri.getEncodedPath());
final Media media = new Media(libVLC, uri);
byte[] bytes = getThumbnail(media, i_width, i_height);
media.release();
return bytes;
}
/**
* Create a Dumper that will download an Uri into a local filesystem path
*
* @param uri the Uri to dump
* @param filepath local filesystem path where to dump the Uri
* @param listener listener in order to be notified when the dump is finished
*/
@MainThread
public Dumper(Uri uri, String filepath, Listener listener) {
if (uri == null || filepath == null || listener == null)
throw new IllegalArgumentException("arguments shouldn't be null");
mListener = listener;
ArrayList<String> options = new ArrayList<>(8);
options.add("--demux");
options.add("dump2,none");
options.add("--demuxdump-file");
options.add(filepath);
options.add("--no-video");
options.add("--no-audio");
options.add("--no-spu");
options.add("-vv");
mLibVLC = new LibVLC(null, options);
final Media media = new Media(mLibVLC, uri);
mMediaPlayer = new MediaPlayer(media);
mMediaPlayer.setEventListener(new MediaPlayer.EventListener() {
@Override
public void onEvent(MediaPlayer.Event event) {
switch (event.type) {
case MediaPlayer.Event.Buffering:
mListener.onProgress(event.getBuffering());
break;
case MediaPlayer.Event.EncounteredError:
case MediaPlayer.Event.EndReached:
mListener.onFinish(event.type == MediaPlayer.Event.EndReached);
cancel();
break;
}
}
});
media.release();
}
/**
* Get a media thumbnail.
* @return a bytearray with the RGBA thumbnail data inside.
*/
public static byte[] getThumbnail(LibVLC libVLC, Uri uri, int i_width, int i_height) {
/* dvd thumbnails can work only with dvdsimple demux */
if (uri.getLastPathSegment().endsWith(".iso"))
uri = Uri.parse("dvdsimple://" + uri.getEncodedPath());
final Media media = new Media(libVLC, uri);
byte[] bytes = getThumbnail(media, i_width, i_height);
media.release();
return bytes;
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void createPresentation() {
if (mMediaRouter == null || mEnableCloneMode)
return;
// Get the current route and its presentation display.
MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute(
MediaRouter.ROUTE_TYPE_LIVE_VIDEO);
Display presentationDisplay = route != null ? route.getPresentationDisplay() : null;
if (presentationDisplay != null) {
// Show a new presentation if possible.
Log.i(TAG, "Showing presentation on display: " + presentationDisplay);
mPresentation = new SecondaryDisplay(this, LibVLC(), presentationDisplay);
mPresentation.setOnDismissListener(mOnDismissListener);
try {
mPresentation.show();
mPresentationDisplayId = presentationDisplay.getDisplayId();
} catch (WindowManager.InvalidDisplayException ex) {
Log.w(TAG, "Couldn't show presentation! Display was removed in "
+ "the meantime.", ex);
mPresentation = null;
}
} else
Log.i(TAG, "No secondary display detected");
}
private MediaPlayer newMediaPlayer() {
final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
final MediaPlayer mp = new MediaPlayer(LibVLC());
final String aout = VLCOptions.getAout(pref);
if (mp.setAudioOutput(aout) && aout.equals("android_audiotrack")) {
mIsAudioTrack = true;
if (mHasHdmiAudio)
mp.setAudioOutputDevice("hdmi");
} else
mIsAudioTrack = false;
mp.getVLCVout().addCallback(this);
return mp;
}
public VLCRendererBuilder(Context context, Uri uri, Properties props) throws ExoPlaybackException {
this.context = context;
this.uri = LibVLC.PathToURI(uri.toString());
this.vlc = ExoVlcUtil.getVLC(context);
this.props = props;
}
/*************
* Activity
*************/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player_activity);
// Receive path to play from intent
Intent intent = getIntent();
if(intent==null|| intent.getExtras()==null || (mFilePath = intent.getExtras().getString(LOCATION))!=null)
mFilePath =LibVLC.PathToURI("/data/local/tmp/air_stunt_1.mp4");
System.out.println("###########################################################");
System.out.println("###########################################################");
System.out.println("###########################################################");
System.out.println("###########################################################");
System.out.println("###########################################################");
System.out.println(">>>> VideoActivity.onCreate() File PATH = "+mFilePath);
System.out.println("###########################################################");
System.out.println("###########################################################");
System.out.println("###########################################################");
System.out.println("###########################################################");
// mFilePath = LibVLC.PathToURI("/data/local/tmp/air_stunt_1.mp4");// intent.getExtras().getString(LOCATION);
// mFilePath = LibVLC.PathToURI("/data/local/tmp/5.0_de.ac3");
Log.d(TAG, "Playing back " + mFilePath);
mSurfaceView = (SurfaceView) findViewById(R.id.surface_view);
mSurfaceHolder = mSurfaceView.getHolder();
setVlcSurface(mSurfaceHolder);
}
/*************
* Player
*************/
LibVLC getLibVLC(){
if(true)
try {
return com.exovlc.ExoVlcUtil.getVLC(this);
} catch (ExoPlaybackException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
finish();
}
throw new IllegalStateException();
}
private synchronized void createPlayer(String media ) {
releasePlayer();
// mSurfaceView.setKeepScreenOn(true);
LibVLC libvlc = getLibVLC();
System.out.println("## Attache vlc lib to surface rec = "+mSurfaceHolder.getSurfaceFrame());
// libvlc.attachSurface(mSurfaceHolder.getSurface(), this);
try {
if (media.length() > 0) {
Toast toast = Toast.makeText(this, media, Toast.LENGTH_LONG);
toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
String[] options = libvlc.getMediaOptions(!true, !libvlc.hasVideoTrack(media));
System.out.println(">>VideoActivity.createPlayer() OPTIONS:");
for (int i = 0; i < options.length; i++)
System.out.println(" o-"+i+":"+options[i]);
libvlc.playMRL(media,options);
System.out.println(" CREATED OPTION WITH : noHardwareAcceleration = !true & noVideo ="+ ! libvlc.hasVideoTrack(media));
System.out.println(">>>>>>>VideoActivity.createPlayer() AUDIOS = "+libvlc.getAudioTracksCount()+ "\n\tAudio track ="+libvlc.getAudioTrack()+ "\n\t VIDEOS = "+ libvlc.getVideoTracksCount() +
"\n\t AUDIO DESCs = " + libvlc. getAudioTrackDescription()+"\n\t HAS VIDEO DESCs = " + libvlc.hasVideoTrack(media)
+"\n\t HAS HardwareAcceleration = " + libvlc.getHardwareAcceleration());
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, "Error creating player!", Toast.LENGTH_LONG).show();
}
}
public VLCRendererBuilder(Context context, Uri uri, Properties props) throws ExoPlaybackException {
this.context = context;
this.uri = LibVLC.PathToURI(uri.toString());
this.vlc = ExoVlcUtil.getVLC(context);
this.props = props;
}