예제 #1
0
  private void releasePlayer() {
    if (mVlcPlayer == null) return;

    mVlcPlayer.setEventListener(null);
    mVlcPlayer.stop();
    mVlcPlayer.getVLCVout().detachViews();
    mVlcPlayer.release();
    mLibVLC = null;
    mVlcPlayer = null;
    mSurfaceView.setKeepScreenOn(false);
  }
예제 #2
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));
    }
  }