Java Code Examples for org.videolan.libvlc.MediaPlayer#setEventListener()

The following examples show how to use org.videolan.libvlc.MediaPlayer#setEventListener() . 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: Dumper.java    From libvlc-android-sdk with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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();
}
 
Example 2
Source File: Dumper.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
/**
 * 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();
}
 
Example 3
Source File: Dumper.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
/**
 * 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();
}
 
Example 4
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 5
Source File: FragmentVideoPlayer.java    From uPods-android with Apache License 2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 6
Source File: Dumper.java    From libvlc-sdk-android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 7
Source File: Dumper.java    From vlc-example-streamplayer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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();
}