コード例 #1
0
 @Override
 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
   if (mVlcPlayer != null) {
     mVlcPlayer.getVLCVout().detachViews();
     mVlcPlayer.getVLCVout().setVideoView(mSurfaceView);
     if (hasSubtitlesSurface) mVlcPlayer.getVLCVout().setSubtitlesView(mSubtitlesSurface);
     mVlcPlayer.getVLCVout().attachViews();
     TvApp.getApplication().getLogger().Debug("Surface attached");
     mSurfaceReady = true;
   }
 }
コード例 #2
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);
  }
コード例 #3
0
 public void setAudioMode() {
   if (!nativeMode) {
     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");
   }
 }
コード例 #4
0
 public void play() {
   if (nativeMode) {
     mVideoView.start();
     mVideoView.setKeepScreenOn(true);
   } else {
     mVlcPlayer.play();
     mSurfaceView.setKeepScreenOn(true);
     // work around losing audio when pausing bug
     int sav = mVlcPlayer.getAudioTrack();
     mVlcPlayer.setAudioTrack(-1);
     mVlcPlayer.setAudioTrack(sav);
     //
   }
 }
コード例 #5
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));
    }
  }
コード例 #6
0
 public void stopPlayback() {
   if (nativeMode) {
     mVideoView.stopPlayback();
   } else {
     mVlcPlayer.stop();
   }
 }
コード例 #7
0
  public void start() {
    if (nativeMode) {
      mVideoView.start();
      mVideoView.setKeepScreenOn(true);
      normalWidth = mVideoView.getLayoutParams().width;
      normalHeight = mVideoView.getLayoutParams().height;
    } else {
      if (!mSurfaceReady) {
        TvApp.getApplication().getLogger().Error("Attempt to play before surface ready");
        return;
      }

      if (!mVlcPlayer.isPlaying()) {
        mVlcPlayer.play();
      }
    }
  }
コード例 #8
0
 public void setAudioDelay(long value) {
   if (!nativeMode && mVlcPlayer != null) {
     if (!mVlcPlayer.setAudioDelay(value * 1000)) {
       TvApp.getApplication().getLogger().Error("Error setting audio delay");
     } else {
       TvApp.getApplication().getLogger().Info("Audio delay set to " + value);
     }
   }
 }
コード例 #9
0
 public void pause() {
   if (nativeMode) {
     mVideoView.pause();
     mVideoView.setKeepScreenOn(false);
   } else {
     mVlcPlayer.pause();
     mSurfaceView.setKeepScreenOn(false);
   }
 }
コード例 #10
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;
      }
    }
  }
コード例 #11
0
  public long getCurrentPosition() {
    if (nativeMode) return mVideoView.getCurrentPosition();

    long time = mVlcPlayer.getTime();
    if (mForcedTime != -1 && mLastTime != -1) {
      /* XXX: After a seek, mLibVLC.getTime can return the position before or after
       * the seek position. Therefore we return mForcedTime in order to avoid the seekBar
       * to move between seek position and the actual position.
       * We have to wait for a valid position (that is after the seek position).
       * to re-init mLastTime and mForcedTime to -1 and return the actual position.
       */
      if (mLastTime > mForcedTime) {
        if (time <= mLastTime && time > mForcedTime) mLastTime = mForcedTime = -1;
      } else {
        if (time > mForcedTime) mLastTime = mForcedTime = -1;
      }
    }
    return mForcedTime == -1 ? time : mForcedTime;
  }
コード例 #12
0
  public void setVideoPath(String path) {
    mCurrentVideoPath = path;

    if (nativeMode) {
      try {
        mVideoView.setVideoPath(path);
      } catch (IllegalStateException e) {
        TvApp.getApplication()
            .getLogger()
            .ErrorException("Unable to set video path.  Probably backing out.", e);
      }
    } else {
      mSurfaceHolder.setKeepScreenOn(true);

      mCurrentMedia = new Media(mLibVLC, Uri.parse(path));
      mCurrentMedia.parse();
      mVlcPlayer.setMedia(mCurrentMedia);

      mCurrentMedia.release();
    }
  }
コード例 #13
0
  public boolean setSubtitleTrack(int index, List<MediaStream> allStreams) {
    if (!nativeMode) {
      // find the relative order of our sub index within the sub tracks in VLC
      int vlcIndex = 1; // start at 1 to account for "disabled"
      for (MediaStream stream : allStreams) {
        if (stream.getType() == MediaStreamType.Subtitle && !stream.getIsExternal()) {
          if (stream.getIndex() == index) {
            break;
          }
          vlcIndex++;
        }
      }

      org.videolan.libvlc.MediaPlayer.TrackDescription vlcSub;
      try {
        vlcSub = getSubtitleTracks()[vlcIndex];

      } catch (IndexOutOfBoundsException e) {
        TvApp.getApplication()
            .getLogger()
            .Error("Could not locate subtitle with index %s in vlc track info", index);
        return false;
      } catch (NullPointerException e) {
        TvApp.getApplication()
            .getLogger()
            .Error(
                "No subtitle tracks found in player trying to set subtitle with index %s in vlc track info",
                index);
        return false;
      }

      TvApp.getApplication().getLogger().Info("Setting Vlc sub to " + vlcSub.name);
      return mVlcPlayer.setSpuTrack(vlcSub.id);
    }

    return false;
  }
コード例 #14
0
 public boolean isPlaying() {
   return nativeMode ? mVideoView.isPlaying() : mVlcPlayer != null && mVlcPlayer.isPlaying();
 }
コード例 #15
0
 public void disableSubs() {
   if (!nativeMode && mVlcPlayer != null) mVlcPlayer.setSpuTrack(-1);
 }
コード例 #16
0
 public boolean canSeek() {
   return nativeMode || mVlcPlayer.isSeekable();
 }
コード例 #17
0
 public org.videolan.libvlc.MediaPlayer.TrackDescription[] getSubtitleTracks() {
   return nativeMode ? null : mVlcPlayer.getSpuTracks();
 }
コード例 #18
0
 public long getAudioDelay() {
   return mVlcPlayer != null ? mVlcPlayer.getAudioDelay() / 1000 : 0;
 }
コード例 #19
0
 public void setCompatibleAudio() {
   if (!nativeMode) {
     mVlcPlayer.setAudioOutput("opensles_android");
     mVlcPlayer.setAudioOutputDevice("hdmi");
   }
 }
コード例 #20
0
 public void setPlaySpeed(float speed) {
   if (!nativeMode) mVlcPlayer.setRate(speed);
 }
コード例 #21
0
 public void setAudioTrack(int id) {
   if (!nativeMode) mVlcPlayer.setAudioTrack(id);
 }
コード例 #22
0
 public int getAudioTrack() {
   return nativeMode ? -1 : mVlcPlayer.getAudioTrack();
 }
コード例 #23
0
 public boolean addSubtitleTrack(String path) {
   return !nativeMode && mVlcPlayer.setSubtitleFile(path);
 }
コード例 #24
0
 public long getDuration() {
   return nativeMode
       ? mVideoView.getDuration()
       : mVlcPlayer.getLength() > 0 ? mVlcPlayer.getLength() : mMetaDuration;
 }
コード例 #25
0
 @Override
 public void surfaceDestroyed(SurfaceHolder holder) {
   if (mVlcPlayer != null) mVlcPlayer.getVLCVout().detachViews();
   mSurfaceReady = false;
 }
コード例 #26
0
 public void updateMeta(MediaPlayer mediaPlayer) {
   final Media media = mediaPlayer.getMedia();
   if (media == null) return;
   updateMeta(media);
   media.release();
 }