Esempio n. 1
0
  private void openVideo() {
    if (mUri == null || mSurfaceHolder == null) 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 AndroidMediaPlayer();
      IjkMediaPlayer ijkMediaPlayer = null;
      if (mUri != null) {
        ijkMediaPlayer = new IjkMediaPlayer();
        ijkMediaPlayer.setAvOption(AvFormatOption_HttpDetectRangeSupport.Disable);
        ijkMediaPlayer.setOverlayFormat(AvFourCC.SDL_FCC_RV32);

        ijkMediaPlayer.setAvCodecOption("skip_loop_filter", "48");
        ijkMediaPlayer.setFrameDrop(12);
        if (mUserAgent != null) {
          ijkMediaPlayer.setAvFormatOption("user_agent", mUserAgent);
        }
      }
      mMediaPlayer = ijkMediaPlayer;
      mMediaPlayer.setOnPreparedListener(mPreparedListener);
      mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
      mMediaPlayer.setOnCompletionListener(mCompletionListener);
      mMediaPlayer.setOnErrorListener(mErrorListener);
      mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
      mMediaPlayer.setOnInfoListener(mInfoListener);
      mMediaPlayer.setOnSeekCompleteListener(mSeekCompleteListener);
      if (mUri != null) mMediaPlayer.setDataSource(mUri.toString());
      mMediaPlayer.setDisplay(mSurfaceHolder);
      mMediaPlayer.setScreenOnWhilePlaying(true);
      mMediaPlayer.prepareAsync();
      mCurrentState = STATE_PREPARING;
      attachMediaController();
    } catch (IOException ex) {
      DebugLog.e(TAG, "Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, IMediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    } catch (IllegalArgumentException ex) {
      DebugLog.e(TAG, "Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, IMediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    }
  }
Esempio n. 2
0
 public void setMediaController(MediaController controller) {
   if (mMediaController != null) mMediaController.hide();
   mMediaController = controller;
   attachMediaController();
 }