private void maybeStartPlayback() {
   Surface surface = mSurfaceView.getHolder().getSurface();
   if (mVideoRenderer == null || surface == null || !surface.isValid()) {
     return;
   }
   mPlayer.sendMessage(mVideoRenderer, MSG_SET_SURFACE, surface);
   if (mAutoPlay) {
     mPlayer.setPlayWhenReady(true);
     mAutoPlay = false;
   }
 }
Exemplo n.º 2
0
  private void pushSurface(boolean blockForSurfacePush) {
    if (videoRenderer == null) {
      return;
    }

    if (blockForSurfacePush) {
      player.blockingSendMessage(
          videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    } else {
      player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    }
  }
Exemplo n.º 3
0
 private void maybeStartPlayback() {
   Log.d(TAG, "maybeStartPlayback");
   Surface surface = surfaceView.getHolder().getSurface();
   if (videoRenderer == null || surface == null || !surface.isValid()) {
     // We're not ready yet.
     return;
   }
   player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
   if (autoPlay) {
     player.setPlayWhenReady(true);
     autoPlay = false;
   }
 }
Exemplo n.º 4
0
  private void pushSurfaceAndVideoTrack(boolean blockForSurfacePush) {
    if (rendererBuildingState != RenderBuildingState.BUILT) {
      return;
    }

    if (blockForSurfacePush) {
      player.blockingSendMessage(
          videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    } else {
      player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    }

    pushTrackSelection(RENDER_VIDEO_INDEX, surface != null && surface.isValid());
  }
Exemplo n.º 5
0
  private void pushTrackSelection(int type, boolean allowRendererEnable) {
    if (rendererBuildingState != RenderBuildingState.BUILT) {
      return;
    }

    int trackIndex = selectedTracks[type];
    if (trackIndex == DISABLED_TRACK) {
      player.setRendererEnabled(type, false);
    } else if (multiTrackSources[type] == null) {
      player.setRendererEnabled(type, allowRendererEnable);
    } else {
      boolean playWhenReady = player.getPlayWhenReady();
      player.setPlayWhenReady(false);
      player.setRendererEnabled(type, false);
      player.sendMessage(
          multiTrackSources[type], MultiTrackChunkSource.MSG_SELECT_TRACK, trackIndex);
      player.setRendererEnabled(type, allowRendererEnable);
      player.setPlayWhenReady(playWhenReady);
    }
  }
Exemplo n.º 6
0
  void initPlayer(String videoLink) {
    if (null == mExoPlayer) {
      mExoPlayer = ExoPlayer.Factory.newInstance(2);
      mPlayerControl = new PlayerControl(mExoPlayer);
      Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
      DataSource dataSource = new DefaultUriDataSource(this, null, USER_AGENT);
      ExtractorSampleSource sampleSource =
          new ExtractorSampleSource(
              Uri.parse(videoLink),
              dataSource,
              allocator,
              BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE);
      MediaCodecVideoTrackRenderer videoRenderer =
          new MediaCodecVideoTrackRenderer(
              sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
      MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);
      mExoPlayer.prepare(videoRenderer, audioRenderer);
      mExoPlayer.sendMessage(
          videoRenderer,
          MediaCodecVideoTrackRenderer.MSG_SET_SURFACE,
          mExoPlayerSurface.getHolder().getSurface());
      mExoPlayer.setPlayWhenReady(true);
    }

    controllerBtn.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
              mPlayerControl.pause();
            } else {
              mPlayerControl.start();
            }
          }
        });

    mSeekBar.setMax(100);
    mSeekBar.setOnSeekBarChangeListener(
        new SeekBar.OnSeekBarChangeListener() {
          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
              updateTime((long) (progress / 100.0f * mExoPlayer.getDuration()));
            }
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {
            controllerBtn.setChecked(true);
            timer.cancel();
          }

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
            mExoPlayer.seekTo((int) (mExoPlayer.getDuration() / 100.0f * seekBar.getProgress()));
          }
        });

    mExoPlayer.addListener(
        new ExoPlayer.Listener() {
          @Override
          public void onPlayerStateChanged(boolean b, int i) {
            if (i == ExoPlayer.STATE_READY) {
              mProgress.setVisibility(View.INVISIBLE);
              timer = new Timer(true);
              timer.schedule(
                  new TimerTask() {
                    @Override
                    public void run() {
                      updateTime(mExoPlayer.getCurrentPosition());
                      updateSeekBar();
                    }
                  },
                  0,
                  1000);
            }
          }

          @Override
          public void onPlayWhenReadyCommitted() {}

          @Override
          public void onPlayerError(ExoPlaybackException e) {}
        });
  }
Exemplo n.º 7
0
 public void setVolume(float volume) {
   player.sendMessage(audioRenderer, MediaCodecAudioTrackRenderer.MSG_SET_VOLUME, volume);
 }