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

The following examples show how to use org.videolan.libvlc.MediaPlayer#play() . 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: 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 2
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();
        }
    }
}