org.videolan.libvlc.Media Java Examples

The following examples show how to use org.videolan.libvlc.Media. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MediaBrowser.java    From libvlc-sdk-android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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");
    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;
}
 
Example #2
Source File: MediaInfoFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
private void updateText() {
    boolean hasSubs = false;
    if (mMedia == null)
        return;
    final int trackCount = mMedia.getTrackCount();
    for (int i = 0; i < trackCount; ++i) {
        final Media.Track track = mMedia.getTrack(i);
        if (track.type == Media.Track.Type.Text)
            hasSubs = true;
        mAdapter.add(track);
    }
    if (mAdapter.isEmpty()) {
        getActivity().finish();
        return;
    }
    if (hasSubs)
        mHandler.obtainMessage(SHOW_SUBTITLES).sendToTarget();
}
 
Example #3
Source File: MediaBrowser.java    From OTTLivePlayer_vlc with MIT License 6 votes vote down vote up
/**
 * 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");
    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;
}
 
Example #4
Source File: PlaybackService.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
public void onEvent(Media.Event event) {
    switch (event.type) {
        case Media.Event.ParsedChanged:
            Log.i(TAG, "Media.Event.ParsedChanged");
            final MediaWrapper mw = getCurrentMedia();
            if (mw != null)
                mw.updateMeta(mMediaPlayer);
            executeUpdate();
            break;
        case Media.Event.MetaChanged:
            break;
    }
    for (Callback callback : mCallbacks)
        callback.onMediaEvent(event);
}
 
Example #5
Source File: ExoVlcUtil.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @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;
}
 
Example #6
Source File: ExoVlcUtil.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @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;
}
 
Example #7
Source File: VlcVideoLibrary.java    From vlc-example-streamplayer with GNU General Public License v3.0 5 votes vote down vote up
private void setMedia(Media media) {
  //delay = network buffer + file buffer
  //media.addOption(":network-caching=" + Constants.BUFFER);
  //media.addOption(":file-caching=" + Constants.BUFFER);
  if (options != null) {
    for (String s : options) {
      media.addOption(s);
    }
  }
  media.setHWDecoderEnabled(true, false);
  player = new MediaPlayer(vlcInstance);
  player.setMedia(media);
  player.setEventListener(this);

  IVLCVout vlcOut = player.getVLCVout();
  //set correct class for render depend of constructor called
  if (surfaceView != null) {
    vlcOut.setVideoView(surfaceView);
    width = surfaceView.getWidth();
    height = surfaceView.getHeight();
  } else if (textureView != null) {
    vlcOut.setVideoView(textureView);
    width = textureView.getWidth();
    height = textureView.getHeight();
  } else if (surfaceTexture != null) {
    vlcOut.setVideoSurface(surfaceTexture);
  } else if (surface != null) {
    vlcOut.setVideoSurface(surface, surfaceHolder);
  } else {
    throw new RuntimeException("You cant set a null render object");
  }
  if (width != 0 && height != 0) vlcOut.setWindowSize(width, height);
  vlcOut.attachViews();
  player.setVideoTrackEnabled(true);
  player.play();
}
 
Example #8
Source File: VLCUtil.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
private void invalidateESTracks(int type) {
    switch (type) {
        case Media.Track.Type.Audio:
            mAudioTracksList = null;
            break;
        case Media.Track.Type.Text:
            mSubtitleTracksList = null;
            break;
    }
}
 
Example #10
Source File: MediaWrapper.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
private void init(Media media) {
    mType = TYPE_ALL;

    if (media != null) {
        if (media.isParsed()) {
            mLength = media.getDuration();

            for (int i = 0; i < media.getTrackCount(); ++i) {
                final Media.Track track = media.getTrack(i);
                if (track == null)
                    continue;
                if (track.type == Media.Track.Type.Video) {
                    final Media.VideoTrack videoTrack = (VideoTrack) track;
                    mType = TYPE_VIDEO;
                    mWidth = videoTrack.width;
                    mHeight = videoTrack.height;
                } else if (mType == TYPE_ALL && track.type == Media.Track.Type.Audio){
                    mType = TYPE_AUDIO;
                }
            }
        }
        updateMeta(media);
        if (mType == TYPE_ALL)
            switch (media.getType()) {
                case Media.Type.Directory:
                    mType = TYPE_DIR;
                    break;
                case Media.Type.Playlist:
                    mType = TYPE_PLAYLIST;
                    break;
            }
        mSlaves = media.getSlaves();
    }
    defineType();
}
 
Example #11
Source File: MediaBrowser.java    From libvlc-android-sdk with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Browse to the specified uri.
 *
 * @param uri
 * @param flags see {@link Flag}
 */
@MainThread
public void browse(Uri uri, int flags) {
    final Media media = new Media(mLibVlc, uri);
    browse(media, flags);
    media.release();
}
 
Example #12
Source File: VLCUtil.java    From libvlc-android-sdk with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: PlaybackService.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@MainThread
public void stop() {
    if (mMediaSession != null) {
        mMediaSession.setActive(false);
        mMediaSession.release();
        mMediaSession = null;
    }
    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);
}
 
Example #14
Source File: VLCUtil.java    From vlc-example-streamplayer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: MediaWrapper.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
public void updateMeta(MediaPlayer mediaPlayer) {
    final Media media = mediaPlayer.getMedia();
    if (media == null)
        return;
    updateMeta(media);
    media.release();
}
 
Example #16
Source File: MediaBrowser.java    From libvlc-sdk-android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Browse to the specified local path starting with '/'.
 *
 * @param path
 * @param flags see {@link MediaBrowser.Flag}
 */
@MainThread
public void browse(String path, int flags) {
    final Media media = new Media(mLibVlc, path);
    browse(media, flags);
    media.release();
}
 
Example #17
Source File: MediaWrapper.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
public void updateMeta(MediaPlayer mediaPlayer) {
    if (!TextUtils.isEmpty(mTitle) && TextUtils.isEmpty(mDisplayTitle))
        mDisplayTitle = mTitle;
    final Media media = mediaPlayer.getMedia();
    if (media == null)
        return;
    updateMeta(media);
    media.release();
}
 
Example #18
Source File: MediaBrowser.java    From libvlc-android-sdk with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Browse to the specified local path starting with '/'.
 *
 * @param path
 * @param flags see {@link Flag}
 */
@MainThread
public void browse(String path, int flags) {
    final Media media = new Media(mLibVlc, path);
    browse(media, flags);
    media.release();
}
 
Example #19
Source File: NetworkBrowserFragment.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
public void onMediaAdded(int index, Media media) {
    addMedia(media);

    if (mUri == null) { // we are at root level
        sort();
    }
    ((BrowserActivityInterface)getActivity()).showProgress(false);
}
 
Example #20
Source File: VLCUtil.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
public static byte[] getThumbnail(Media media, int i_width, int i_height) {
    media.addOption(":no-audio");
    media.addOption(":no-spu");
    media.addOption(":no-osd");
    media.addOption(":input-fast-seek");
    return nativeGetThumbnail(media, i_width, i_height);
}
 
Example #21
Source File: VLCUtil.java    From libvlc-sdk-android with GNU General Public License v2.0 5 votes vote down vote up
public static byte[] getThumbnail(Media media, int i_width, int i_height) {
    media.addOption(":no-audio");
    media.addOption(":no-spu");
    media.addOption(":no-osd");
    media.addOption(":input-fast-seek");
    return nativeGetThumbnail(media, i_width, i_height);
}
 
Example #22
Source File: MediaBrowser.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
/**
 * Browse to the specified local path starting with '/'.
 *
 * @param path
 * @param flags see {@link MediaBrowser.Flag}
 */
@MainThread
public void browse(String path, int flags) {
    final Media media = new Media(mLibVlc, path);
    browse(media, flags);
    media.release();
}
 
Example #23
Source File: MediaBrowser.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
/**
 * Browse to the specified uri.
 *
 * @param uri
 * @param flags see {@link MediaBrowser.Flag}
 */
@MainThread
public void browse(Uri uri, int flags) {
    final Media media = new Media(mLibVlc, uri);
    browse(media, flags);
    media.release();
}
 
Example #24
Source File: VideoGridFragment.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
private void setContextMenuItems(Menu menu, MediaWrapper mediaWrapper) {
    long lastTime = mediaWrapper.getTime();
    if (lastTime > 0)
        menu.findItem(R.id.video_list_play_from_start).setVisible(true);

    boolean hasInfo = false;
    final Media media = new Media(VLCInstance.get(), mediaWrapper.getUri());
    media.parse();
    if (media.getMeta(Media.Meta.Title) != null)
        hasInfo = true;
    media.release();
    menu.findItem(R.id.video_list_info).setVisible(hasInfo);
    menu.findItem(R.id.video_list_delete).setVisible(!AndroidUtil.isLolliPopOrLater() ||
            mediaWrapper.getLocation().startsWith("file://" + AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY));
}
 
Example #25
Source File: MediaWrapper.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
/**
 * Create a new MediaWrapper
 * @param media should be parsed and not NULL
 */
public MediaWrapper(Media media) {
    super();
    if (media == null)
        throw new NullPointerException("media was null");

    mUri = media.getUri();
    init(media);
}
 
Example #26
Source File: MediaWrapper.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
private void init(Media media) {
    mType = TYPE_ALL;

    if (media != null) {
        if (media.isParsed()) {
            mLength = media.getDuration();

            for (int i = 0; i < media.getTrackCount(); ++i) {
                final Media.Track track = media.getTrack(i);
                if (track == null)
                    continue;
                if (track.type == Media.Track.Type.Video) {
                    final Media.VideoTrack videoTrack = (VideoTrack) track;
                    mType = TYPE_VIDEO;
                    mWidth = videoTrack.width;
                    mHeight = videoTrack.height;
                } else if (mType == TYPE_ALL && track.type == Media.Track.Type.Audio){
                    mType = TYPE_AUDIO;
                }
            }
        }
        updateMeta(media);
        if (mType == TYPE_ALL)
            switch (media.getType()) {
                case Media.Type.Directory:
                    mType = TYPE_DIR;
                    break;
                case Media.Type.Playlist:
                    mType = TYPE_PLAYLIST;
                    break;
            }
        mSlaves = media.getSlaves();
    }
    defineType();
}
 
Example #27
Source File: MediaBrowser.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
/**
 * Browse to the specified media.
 *
 * @param media Can be a media returned by MediaBrowser.
 */
public synchronized void browse(Media media) {
    /* media can be associated with a medialist,
     * so increment ref count in order to don't clean it with the medialist
     */
    media.retain();
    reset();
    mBrowserMediaList = media.subItems();
    mBrowserMediaList.setEventListener(mBrowserMediaListEventListener);
    media.parseAsync(Media.Parse.ParseNetwork);
    mMedia = media;
}
 
Example #28
Source File: MediaBrowser.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
/**
 * Browse to the specified uri.
 *
 * @param uri
 * @param flags see {@link MediaBrowser.Flag}
 */
@MainThread
public void browse(Uri uri, int flags) {
    final Media media = new Media(mLibVlc, uri);
    browse(media, flags);
    media.release();
}
 
Example #29
Source File: MediaBrowser.java    From libvlc-sdk-android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Browse to the specified uri.
 *
 * @param uri
 * @param flags see {@link MediaBrowser.Flag}
 */
@MainThread
public void browse(Uri uri, int flags) {
    final Media media = new Media(mLibVlc, uri);
    browse(media, flags);
    media.release();
}
 
Example #30
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onMediaEvent(Media.Event event) {
    switch (event.type) {
        case Media.Event.ParsedChanged:
            updateNavStatus();
            break;
        case Media.Event.MetaChanged:
            break;
        case Media.Event.SubItemTreeAdded:
            mHasSubItems = true;
            break;
    }
}