Esempio n. 1
0
  private void openVideo() {
    if (mUri == null || mPlayer == null) return;

    mPlayer.reset();
    mInitialized = false;
    mPrepared = false;
    mVideoSizeKnown = false;

    try {
      mPlayer.setScreenOnWhilePlaying(true);
      mPlayer.setDataSource(PlayerService.this, mUri);
      // if (mLastAudioTrack != -1)
      // mPlayer.setInitialAudioTrack(mLastAudioTrack);
      // if (mLastSubTrackId != -1)
      // mPlayer.setInitialSubTrack(mLastSubTrackId);
      if (mSurfaceHolder != null
          && mSurfaceHolder.getSurface() != null
          && mSurfaceHolder.getSurface().isValid()) mPlayer.setDisplay(mSurfaceHolder);
      mPlayer.prepareAsync();
    } catch (IllegalArgumentException e) {
      Logger.e("openVideo", e);
    } catch (IllegalStateException e) {
      Logger.e("openVideo", e);
    } catch (IOException e) {
      Logger.e("openVideo", e);
    }
  }
Esempio n. 2
0
  private void openVideo() {
    if (mUri == null || mSurfaceHolder == null || !Vitamio.isInitialized(mContext)) return;

    Intent i = new Intent("com.android.music.musicservicecommand");
    i.putExtra("command", "pause");
    mContext.sendBroadcast(i);

    release(false);
    try {
      mDuration = -1;
      mCurrentBufferPercentage = 0;
      mMediaPlayer = new MediaPlayer(mContext);
      mMediaPlayer.setOnPreparedListener(mPreparedListener);
      mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
      mMediaPlayer.setOnCompletionListener(mCompletionListener);
      mMediaPlayer.setOnErrorListener(mErrorListener);
      mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
      mMediaPlayer.setOnInfoListener(mInfoListener);
      mMediaPlayer.setOnSeekCompleteListener(mSeekCompleteListener);
      mMediaPlayer.setOnTimedTextListener(mTimedTextListener);
      mMediaPlayer.setDataSource(mContext, mUri);
      mMediaPlayer.setDisplay(mSurfaceHolder);
      mMediaPlayer.setScreenOnWhilePlaying(true);
      mMediaPlayer.prepareAsync();
      mCurrentState = STATE_PREPARING;
      attachMediaController();
    } catch (IOException ex) {
      Log.e("Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    } catch (IllegalArgumentException ex) {
      Log.e("Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    }
  }