本文整理汇总了Java中org.videolan.libvlc.Media类的典型用法代码示例。如果您正苦于以下问题:Java Media类的具体用法?Java Media怎么用?Java Media使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Media类属于org.videolan.libvlc包,在下文中一共展示了Media类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPlayer
import org.videolan.libvlc.Media; //导入依赖的package包/类
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();
}
}
}
示例2: onMediaPlayerEvent
import org.videolan.libvlc.Media; //导入依赖的package包/类
@Override
public void onMediaPlayerEvent(MediaPlayer.Event event) {
switch (event.type) {
case MediaPlayer.Event.Opening:
mSwitchedToVideo = false;
break;
case MediaPlayer.Event.ESAdded:
final boolean forceAudio = (mService.getCurrentMediaWrapper().getFlags() & MediaWrapper.MEDIA_FORCE_AUDIO) != 0;
if (!forceAudio && !mSwitchedToVideo && event.getEsChangedType() == Media.Track.Type.Video) {
mService.switchToVideo();
mSwitchedToVideo = true;
}
break;
case MediaPlayer.Event.Stopped:
hide();
break;
}
}
示例3: browse
import org.videolan.libvlc.Media; //导入依赖的package包/类
/**
* Browse to the specified media.
*
* @param media Can be a media returned by MediaBrowser.
* @param flags see {@link Flag}
*/
@MainThread
public void browse(Media media, int flags) {
/* media can be associated with a medialist,
* so increment ref count in order to don't clean it with the medialist
*/
media.retain();
media.addOption(IGNORE_LIST_OPTION + mIgnoreList);
if ((flags & Flag.NoSlavesAutodetect) != 0)
media.addOption(":no-sub-autodetect-file");
if ((flags & Flag.ShowHiddenFiles) != 0)
media.addOption(":show-hiddenfiles");
int mediaFlags = Media.Parse.ParseNetwork;
if ((flags & Flag.Interact) != 0)
mediaFlags |= Media.Parse.DoInteract;
reset();
mBrowserMediaList = media.subItems();
mBrowserMediaList.setEventListener(mBrowserMediaListEventListener, mHandler);
media.parseAsync(mediaFlags, 0);
mMedia = media;
}
示例4: setSrc
import org.videolan.libvlc.Media; //导入依赖的package包/类
public void setSrc(final String uriString) {
mSrcUriString = uriString;
createPlayer();
Media m = new Media(libvlc, Uri.parse(uriString));
mMediaPlayer.setMedia(m);
//mMediaPlayer.play(); // Maybe it's better to call that only through updateModifiers()
// We need this because on the Opening event, we do not get Duration
mLoaded = false;
// Because the VLC buffering event and state is a bit wonky
mStalled = false;
WritableMap src = Arguments.createMap();
src.putString(ReactVideoViewManager.PROP_SRC_URI, uriString);
WritableMap event = Arguments.createMap();
event.putMap(ReactVideoViewManager.PROP_SRC, src);
mEventEmitter.receiveEvent(getId(), Events.EVENT_LOAD_START.toString(), event);
}
示例5: setMediaOptions
import org.videolan.libvlc.Media; //导入依赖的package包/类
public static void setMediaOptions(Media media, Context context, int flags) {
boolean noHardwareAcceleration = (flags & MEDIA_NO_HWACCEL) != 0;
boolean noVideo = (flags & MEDIA_VIDEO) == 0;
final boolean paused = (flags & MEDIA_PAUSED) != 0;
int hardwareAcceleration = HW_ACCELERATION_DISABLED;
if (!noHardwareAcceleration) {
try {
hardwareAcceleration = PrefUtils.get(context, Prefs.HW_ACCELERATION, HW_ACCELERATION_AUTOMATIC);
} catch (NumberFormatException ignored) {}
}
if (hardwareAcceleration == HW_ACCELERATION_DISABLED)
media.setHWDecoderEnabled(false, false);
else if (hardwareAcceleration == HW_ACCELERATION_FULL || hardwareAcceleration == HW_ACCELERATION_DECODING) {
media.setHWDecoderEnabled(true, true);
if (hardwareAcceleration == HW_ACCELERATION_DECODING) {
media.addOption(":no-mediacodec-dr");
media.addOption(":no-omxil-dr");
}
} /* else automatic: use default options */
if (noVideo)
media.addOption(":no-video");
if (paused)
media.addOption(":start-paused");
}
示例6: onStart
import org.videolan.libvlc.Media; //导入依赖的package包/类
@Override
protected void onStart() {
super.onStart();
final IVLCVout vlcVout = mMediaPlayer.getVLCVout();
// final IVLCVout vlcVout2 = mMediaPlayer2.getVLCVout();
vlcVout.setVideoView(mVideoSurface);
// vlcVout2.setVideoView(mVideoSurface1);
vlcVout.attachViews();
// vlcVout2.attachViews();
mMediaPlayer.getVLCVout().addCallback(this);
// mMediaPlayer2.getVLCVout().addCallback(this);
Media media = new Media(mLibVLC, Uri.parse(SAMPLE_URL));
// Media media1 = new Media(mLibVLC, Uri.parse(SAMPLE_URL1));
mMediaPlayer.setMedia(media);
// mMediaPlayer2.setMedia(media1);
media.release();
mMediaPlayer.play();
// mMediaPlayer2.play();
// mMediaPlayer.setRate(.5f);
}
示例7: browse
import org.videolan.libvlc.Media; //导入依赖的package包/类
/**
* Browse to the specified media.
*
* @param media Can be a media returned by MediaBrowser.
* @param flags see {@link MediaBrowser.Flag}
*/
@MainThread
public void browse(Media media, int flags) {
/* media can be associated with a medialist,
* so increment ref count in order to don't clean it with the medialist
*/
media.retain();
media.addOption(IGNORE_LIST_OPTION + mIgnoreList);
if ((flags & Flag.NoSlavesAutodetect) != 0)
media.addOption(":no-sub-autodetect-file");
int mediaFlags = Media.Parse.ParseNetwork;
if ((flags & Flag.Interact) != 0)
mediaFlags |= Media.Parse.DoInteract;
reset();
mBrowserMediaList = media.subItems();
mBrowserMediaList.setEventListener(mBrowserMediaListEventListener);
media.parseAsync(mediaFlags, 0);
mMedia = media;
}
示例8: stop
import org.videolan.libvlc.Media; //导入依赖的package包/类
@MainThread
public void stop() {
if (mMediaPlayer == null)
return;
savePosition();
final Media media = mMediaPlayer.getMedia();
if (media != null) {
media.setEventListener(null);
mMediaPlayer.setEventListener(null);
mMediaPlayer.stop();
mMediaPlayer.setMedia(null);
media.release();
}
mMediaList.removeEventListener(mListEventListener);
setRemoteControlClientPlaybackState(MediaPlayer.Event.Stopped);
mCurrentIndex = -1;
mPrevious.clear();
mHandler.removeMessages(SHOW_PROGRESS);
hideNotification();
broadcastMetadata();
executeUpdate();
executeUpdateProgress();
changeAudioFocus(false);
}
示例9: expand
import org.videolan.libvlc.Media; //导入依赖的package包/类
/**
* Expand the current media.
* @return the index of the media was expanded, and -1 if no media was expanded
*/
@MainThread
public int expand() {
final Media media = mMediaPlayer.getMedia();
if (media == null)
return -1;
final MediaList ml = media.subItems();
media.release();
int ret;
if (ml.getCount() > 0) {
mMediaList.remove(mCurrentIndex);
for (int i = 0; i < ml.getCount(); ++i) {
final Media child = ml.getMediaAt(i);
child.parse();
mMediaList.insert(mCurrentIndex, new MediaWrapper(child));
child.release();
}
ret = 0;
} else {
ret = -1;
}
ml.release();
return ret;
}
示例10: vlc2exoTracks
import org.videolan.libvlc.Media; //导入依赖的package包/类
/**
*
* @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;
}
示例11: expand
import org.videolan.libvlc.Media; //导入依赖的package包/类
/**
* Expand the current media.
* @return the index of the media was expanded, and -1 if no media was expanded
*/
@MainThread
public int expand() {
final Media media = mMediaPlayer.getMedia();
if (media == null)
return -1;
final MediaList ml = media.subItems();
media.release();
int ret;
if (ml.getCount() > 0) {
mMediaList.remove(mCurrentIndex);
for (int i = ml.getCount() - 1; i >= 0; --i) {
final Media child = ml.getMediaAt(i);
child.parse();
mMediaList.insert(mCurrentIndex, new MediaWrapper(child));
child.release();
}
ret = 0;
} else {
ret = -1;
}
ml.release();
return ret;
}
示例12: createPlayer
import org.videolan.libvlc.Media; //导入依赖的package包/类
private void createPlayer(String mediaUrl) {
releasePlayer();
if(mediaUrl.isEmpty()) return;
try {
// Create LibVLC
mLibvlc = new LibVLC();
// Create media player
mMediaPlayer = new MediaPlayer(mLibvlc);
final IVLCVout vout = mMediaPlayer.getVLCVout();
vout.setVideoView(mSurfaceView);
vout.addCallback(this);
vout.attachViews();
final Media media = new Media(mLibvlc, Uri.parse(mediaUrl));
mMediaPlayer.setMedia(media);
mMediaPlayer.setEventListener(listener);
//media.release();
if(mIsPlaying) {
startPlayer();
}
} catch (Exception e) {
Toast.makeText(this, "Error creating player!", Toast.LENGTH_LONG).show();
}
}
示例13: getMediaAt
import org.videolan.libvlc.Media; //导入依赖的package包/类
/**
* Get a media at a specified index. Should be released with {@link #release()}.
*/
@MainThread
public Media getMediaAt(int index) {
if (index < 0 || index >= getMediaCount())
throw new IndexOutOfBoundsException();
final Media media = mBrowserMediaList != null ? mBrowserMediaList.getMediaAt(index) :
mDiscovererMediaArray.get(index);
media.retain();
return media;
}
示例14: getThumbnail
import org.videolan.libvlc.Media; //导入依赖的package包/类
/**
* 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;
}
示例15: Dumper
import org.videolan.libvlc.Media; //导入依赖的package包/类
/**
* 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();
}