Пример #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);
    }
  }
 private void setupMedia() {
   doCleanUp();
   try {
     mMediaPlayer.setDataSource(extras.getString("mediaUrl"));
     mMediaPlayer.setDisplay(holder);
     mMediaPlayer.prepareAsync();
   } catch (Exception e) {
     Log.e(TAG, "error: " + e.getMessage(), e);
   }
 }
Пример #3
0
 private void preparePlayer() {
   if (player == null) {
     player = new MediaPlayer(this);
     playerNeedsPrepare = true;
     mediaController.setMediaPlayer(player);
     mediaController.setEnabled(true);
   }
   if (playerNeedsPrepare) {
     player.prepareAsync();
     playerNeedsPrepare = false;
   }
   player.setSurface(surfaceView.getHolder().getSurface());
   player.start();
 }
Пример #4
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;
    }
  }
Пример #5
0
  private void playVideo() {
    doCleanUp();
    try {

      // Create a new media player and set the listeners
      player = new MediaPlayer(this);
      player.setDataSource(
          "http://htqjrpsv.cdnviet.com/htjzzsg/_definst_/vtv3.720p.stream/playlist.m3u8?t=b4781bdd2251d0e465e92824e9a11cf9&e=1428759643");
      player.setDisplay(holder);
      player.prepareAsync();
      player.setOnPreparedListener(this);
      player.setOnErrorListener(this);
      // player.setOnVideoSizeChangedListener(this);
      setVolumeControlStream(AudioManager.STREAM_MUSIC);
      mediaController.setMediaPlayer(player);
      mediaController.setEnabled(true);
      // player.setSurface(surfaceView.getHolder().getSurface());
      // player.start();
      mediaController.showLoading(0);

    } catch (Exception e) {
      Log.e(TAG, "error: " + e.getMessage(), e);
    }
  }
Пример #6
0
  private void playVideo(Integer Media) {
    doCleanUp();
    try {

      switch (Media) {
        case LOCAL_VIDEO:
          /*
           * TODO: Set the path variable to a local media file path.
           */
          path = "";
          if (path == "") {
            // Tell the user to provide a media file URL.
            Toast.makeText(
                    MediaPlayerDemo_Video.this,
                    "Please edit MediaPlayerDemo_Video Activity, "
                        + "and set the path variable to your media file path."
                        + " Your media file must be stored on sdcard.",
                    Toast.LENGTH_LONG)
                .show();
            return;
          }
          break;
        case STREAM_VIDEO:
          /*
           * TODO: Set path variable to progressive streamable mp4 or
           * 3gpp format URL. Http protocol should be used.
           * Mediaplayer can only play "progressive streamable
           * contents" which basically means: 1. the movie atom has to
           * precede all the media data atoms. 2. The clip has to be
           * reasonably interleaved.
           *
           */

          if (path == "") {
            // Tell the user to provide a media file URL.
            Toast.makeText(
                    MediaPlayerDemo_Video.this,
                    "Please edit MediaPlayerDemo_Video Activity,"
                        + " and set the path variable to your media file URL.",
                    Toast.LENGTH_LONG)
                .show();
            return;
          }

          break;
      }

      // Create a new media player and set the listeners
      mMediaPlayer = new MediaPlayer(this);
      mMediaPlayer.setDataSource(path);
      mMediaPlayer.setDisplay(holder);
      mMediaPlayer.prepareAsync();
      mMediaPlayer.setOnBufferingUpdateListener(this);
      mMediaPlayer.setOnCompletionListener(this);
      mMediaPlayer.setOnPreparedListener(this);
      mMediaPlayer.setOnVideoSizeChangedListener(this);
      setVolumeControlStream(AudioManager.STREAM_MUSIC);

    } catch (Exception e) {
      Log.e(TAG, "error: " + e.getMessage(), e);
    }
  }