Ejemplo n.º 1
0
  private void createPlayer(int buffer) {
    try {

      // Create a new media player
      ArrayList<String> options = new ArrayList<>(20);
      options.add("--network-caching=" + buffer);
      options.add("--no-audio-time-stretch");
      options.add("--androidwindow-chroma");
      options.add("RV32");
      //            options.add("--subsdec-encoding");
      //            options.add("Universal (UTF-8)");
      options.add("-v");

      mLibVLC = new LibVLC(options);
      TvApp.getApplication().getLogger().Info("Network buffer set to " + buffer);
      LibVLC.setOnNativeCrashListener(
          new LibVLC.OnNativeCrashListener() {
            @Override
            public void onNativeCrash() {
              new Exception().printStackTrace();
              Utils.PutCustomAcraData();
              ACRA.getErrorReporter().handleException(new Exception("Error in LibVLC"), false);
              mActivity.finish();
              android.os.Process.killProcess(android.os.Process.myPid());
              System.exit(10);
            }
          });

      mVlcPlayer = new org.videolan.libvlc.MediaPlayer(mLibVLC);
      SharedPreferences prefs = TvApp.getApplication().getPrefs();
      String audioOption =
          Utils.isFireTv() && !Utils.is50()
              ? "1"
              : prefs.getString("pref_audio_option", "0"); // force compatible audio on Fire 4.2
      mVlcPlayer.setAudioOutput(
          "0".equals(audioOption) ? "android_audiotrack" : "opensles_android");
      mVlcPlayer.setAudioOutputDevice("hdmi");

      mSurfaceHolder.addCallback(mSurfaceCallback);
      mVlcPlayer.setEventListener(mVlcHandler);
      mVlcPlayer.getVLCVout().addCallback(this);

    } catch (Exception e) {
      TvApp.getApplication().getLogger().ErrorException("Error creating VLC player", e);
      Utils.showToast(
          TvApp.getApplication(),
          TvApp.getApplication().getString(R.string.msg_video_playback_error));
    }
  }
Ejemplo n.º 2
0
  public long seekTo(long pos) {
    if (nativeMode) {
      Long intPos = pos;
      mVideoView.seekTo(intPos.intValue());
      return pos;
    } else {
      if (mVlcPlayer == null || !mVlcPlayer.isSeekable()) return -1;
      mForcedTime = pos;
      mLastTime = mVlcPlayer.getTime();
      TvApp.getApplication().getLogger().Info("VLC length in seek is: " + mVlcPlayer.getLength());
      try {
        if (getDuration() > 0) mVlcPlayer.setPosition((float) pos / getDuration());
        else mVlcPlayer.setTime(pos);

        return pos;

      } catch (Exception e) {
        TvApp.getApplication().getLogger().ErrorException("Error seeking in VLC", e);
        Utils.showToast(mActivity, "Unable to seek");
        return -1;
      }
    }
  }