com.google.android.exoplayer.util.PlayerControl Java Examples

The following examples show how to use com.google.android.exoplayer.util.PlayerControl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DemoPlayer.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
public DemoPlayer(RendererBuilder rendererBuilder) {
  this.rendererBuilder = rendererBuilder;
  //###AXT:: --> try to start the player without internal buffering. We do buffering in Raw Sample sources
  // player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
  player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, -1, -1);
  //###AXT:: <--
  player.addListener(this);
  playerControl = new PlayerControl(player);
  mainHandler = new Handler();
  listeners = new CopyOnWriteArrayList<Listener>();
  lastReportedPlaybackState = STATE_IDLE;
  rendererBuildingState = RENDERER_BUILDING_STATE_IDLE;
  selectedTracks = new int[RENDERER_COUNT];
  // Disable text initially.
  selectedTracks[TYPE_TEXT] = DISABLED_TRACK;
}
 
Example #2
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
private void preparePlayer() {

        SampleSource sampleSource =
                new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT);

        // Build the track renderers
        videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
        TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

        // Setup the player
        player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
        player.addListener(this);
        // Build the player controls
        mediaController.setMediaPlayer(new PlayerControl(player));
        mediaController.setEnabled(true);
        player.prepare(videoRenderer, audioRenderer);
    }
 
Example #3
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
private void preparePlayer() {

        SampleSource sampleSource =
                new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT);

        // Build the track renderers
        videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
        TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

        // Setup the player
        player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
        player.addListener(this);
        // Build the player controls
        mediaController.setMediaPlayer(new PlayerControl(player));
        mediaController.setEnabled(true);
        player.prepare(videoRenderer, audioRenderer);
    }
 
Example #4
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
private void preparePlayer() {

        SampleSource sampleSource =
                new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT);

        // Build the track renderers
        videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
        TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);


        // Setup the player
        player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
        player.addListener(this);
        // Build the player controls
        mediaController.setMediaPlayer(new PlayerControl(player));
        mediaController.setEnabled(true);
        player.prepare(videoRenderer, audioRenderer);
    }
 
Example #5
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
private void preparePlayer() {

        SampleSource sampleSource =
                new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT);

        // Build the track renderers
        videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
        TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

        // Setup the player
        player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
        player.addListener(this);
        // Build the player controls
        mediaController.setMediaPlayer(new PlayerControl(player));
        mediaController.setEnabled(true);
        player.prepare(videoRenderer, audioRenderer);
    }
 
Example #6
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    View root = findViewById(R.id.root);
    mediaController = new MediaController(this);

    //overscan safe on 1980 * 1080 TV
    mediaController.setPadding(48, 27, 48, 27);
    mediaController.setAnchorView(root);
    shutterView = findViewById(R.id.shutter);
    surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    SampleSource sampleSource =
            new FrameworkSampleSource(this, Uri.parse(url), /* headers */ null, RENDERER_COUNT);

    // Build the track renderers
    videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
    TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

    // Setup the player
    player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
    player.addListener(this);
    // Build the player controls
    mediaController.setMediaPlayer(new PlayerControl(player));
    mediaController.setEnabled(true);
    player.prepare(videoRenderer, audioRenderer);
}
 
Example #7
Source File: PlaybackControlLayer.java    From google-media-framework-android with Apache License 2.0 5 votes vote down vote up
/**
 * Adjust the position of the action bar to reflect the progress of the video.
 */
public int updateProgress() {
  PlayerControl playerControl = getLayerManager().getControl();
  if (playerControl == null || isSeekbarDragging) {
    return 0;
  }

  int position = playerControl.getCurrentPosition();
  int duration = playerControl.getDuration();

  if (seekBar != null) {
    if (duration > 0) {
      long pos = 1000L * position / duration;
      seekBar.setProgress((int) pos);
    }

    int percent = playerControl.getBufferPercentage();
    seekBar.setSecondaryProgress(percent * 10);
  }

  if (endTime != null) {
    endTime.setText(stringForTime(duration));
  }
  if (currentTime != null) {
    currentTime.setText(stringForTime(position));
  }

  return position;
}
 
Example #8
Source File: PlaybackControlLayer.java    From google-media-framework-android with Apache License 2.0 5 votes vote down vote up
/**
 * Change the icon of the play/pause button to indicate play or pause based on the state of the
 * video player.
 */
public void updatePlayPauseButton() {
  PlayerControl playerControl = getLayerManager().getControl();
  if (view == null || pausePlayButton == null || playerControl == null) {
    return;
  }

  if (playerControl.isPlaying()) {
    pausePlayButton.setImageResource(R.drawable.ic_action_pause_large);
  } else {
    pausePlayButton.setImageResource(R.drawable.ic_action_play_large);
  }
}
 
Example #9
Source File: PlaybackControlLayer.java    From google-media-framework-android with Apache License 2.0 5 votes vote down vote up
/**
 * Play or pause the player.
 * @param shouldPlay If true, then the player starts playing. If false, the player pauses.
 */
public void setPlayPause(boolean shouldPlay) {
  PlayerControl playerControl = getLayerManager().getControl();
  if (playerControl == null) {
    return;
  }

  if (shouldPlay) {
    playerControl.start();
  } else {
    playerControl.pause();
  }

  updatePlayPauseButton();
}
 
Example #10
Source File: DemoPlayer.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
public DemoPlayer(RendererBuilder rendererBuilder) {
    this.rendererBuilder = rendererBuilder;
    player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
    player.addListener(this);
    playerControl = new PlayerControl(player);
    mainHandler = new Handler();
    listeners = new CopyOnWriteArrayList<>();
    mTvPlayerCallbacks = new CopyOnWriteArrayList<>();
    lastReportedPlaybackState = STATE_IDLE;
    rendererBuildingState = RENDERER_BUILDING_STATE_IDLE;
    // Disable text initially.
    player.setSelectedTrack(TYPE_TEXT, TRACK_DISABLED);
}
 
Example #11
Source File: DemoPlayer.java    From Mobilyzer with Apache License 2.0 5 votes vote down vote up
public DemoPlayer(RendererBuilder rendererBuilder) {
  this.rendererBuilder = rendererBuilder;
  player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
  player.addListener(this);
  playerControl = new PlayerControl(player);
  mainHandler = new Handler();
  listeners = new CopyOnWriteArrayList<Listener>();
  lastReportedPlaybackState = STATE_IDLE;
  rendererBuildingState = RENDERER_BUILDING_STATE_IDLE;
  selectedTracks = new int[RENDERER_COUNT];
  // Disable text initially.
  selectedTracks[TYPE_TEXT] = DISABLED_TRACK;
}
 
Example #12
Source File: DemoPlayer.java    From droidkaigi2016 with Apache License 2.0 5 votes vote down vote up
public DemoPlayer(RendererBuilder rendererBuilder) {
  this.rendererBuilder = rendererBuilder;
  player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
  player.addListener(this);
  playerControl = new PlayerControl(player);
  mainHandler = new Handler();
  listeners = new CopyOnWriteArrayList<>();
  lastReportedPlaybackState = STATE_IDLE;
  rendererBuildingState = RENDERER_BUILDING_STATE_IDLE;
  // Disable text initially.
  player.setSelectedTrack(TYPE_TEXT, TRACK_DISABLED);
}
 
Example #13
Source File: VideoPlayer.java    From iview-android-tv with MIT License 5 votes vote down vote up
public VideoPlayer(RendererBuilder rendererBuilder) {
    this.rendererBuilder = rendererBuilder;
    player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
    player.addListener(this);
    playerControl = new PlayerControl(player);
    mainHandler = new Handler();
    listeners = new CopyOnWriteArrayList<>();
    lastReportedPlaybackState = STATE_IDLE;
    rendererBuildingState = RENDERER_BUILDING_STATE_IDLE;
    selectedTracks = new int[RENDERER_COUNT];
    // Disable text initially.
    selectedTracks[TYPE_TEXT] = DISABLED_TRACK;
}
 
Example #14
Source File: Player.java    From exoplayer-textureview with Apache License 2.0 5 votes vote down vote up
public Player() {
    eventProxy = new EventProxy();
    eventProxy.setPlayer(this);
    player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
    player.addListener(this);
    playerControl = new PlayerControl(player);
    listeners = new CopyOnWriteArrayList<>();
    lastReportedPlaybackState = STATE_IDLE;
    rendererBuildingState = RENDERER_BUILDING_STATE_IDLE;
    // Disable text initially.
    player.setSelectedTrack(TYPE_TEXT, TRACK_DISABLED);
}
 
Example #15
Source File: DemoPlayer.java    From AndroidTvDemo with Apache License 2.0 5 votes vote down vote up
public DemoPlayer(RendererBuilder rendererBuilder) {
  this.rendererBuilder = rendererBuilder;
  player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
  player.addListener(this);
  playerControl = new PlayerControl(player);
  mainHandler = new Handler();
  listeners = new CopyOnWriteArrayList<>();
  lastReportedPlaybackState = STATE_IDLE;
  rendererBuildingState = RENDERER_BUILDING_STATE_IDLE;
  // Disable text initially.
  player.setSelectedTrack(TYPE_TEXT, TRACK_DISABLED);
}
 
Example #16
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    View root = findViewById(R.id.root);
    mediaController = new MediaController(this);

    //overscan safe on 1980 * 1080 TV
    mediaController.setPadding(48, 27, 48, 27);
    mediaController.setAnchorView(root);
    shutterView = findViewById(R.id.shutter);
    surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    SampleSource sampleSource =
            new FrameworkSampleSource(this, Uri.parse(url), /* headers */ null, RENDERER_COUNT);

    // Build the track renderers
    videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
    TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

    // Setup the player
    player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
    player.addListener(this);
    // Build the player controls
    mediaController.setMediaPlayer(new PlayerControl(player));
    mediaController.setEnabled(true);
    player.prepare(videoRenderer, audioRenderer);
}
 
Example #17
Source File: DemoPlayer.java    From Android-Example-HLS-ExoPlayer with Apache License 2.0 5 votes vote down vote up
public DemoPlayer(RendererBuilder rendererBuilder) {
  this.rendererBuilder = rendererBuilder;
  player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
  player.addListener(this);
  playerControl = new PlayerControl(player);
  mainHandler = new Handler();
  listeners = new CopyOnWriteArrayList<>();
  lastReportedPlaybackState = STATE_IDLE;
  rendererBuildingState = RENDERER_BUILDING_STATE_IDLE;
  // Disable text initially.
  player.setSelectedTrack(TYPE_TEXT, TRACK_DISABLED);
}
 
Example #18
Source File: DemoPlayer.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
public DemoPlayer(RendererBuilder rendererBuilder) {
  this.rendererBuilder = rendererBuilder;
  player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
  player.addListener(this);
  playerControl = new PlayerControl(player);
  mainHandler = new Handler();
  listeners = new CopyOnWriteArrayList<>();
  lastReportedPlaybackState = STATE_IDLE;
  rendererBuildingState = RENDERER_BUILDING_STATE_IDLE;
  // Disable text initially.
  player.setSelectedTrack(TYPE_TEXT, TRACK_DISABLED);
}
 
Example #19
Source File: DemoPlayer.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
public DemoPlayer(RendererBuilder rendererBuilder) {
  this.rendererBuilder = rendererBuilder;
  player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
  player.addListener(this);
  playerControl = new PlayerControl(player);
  mainHandler = new Handler();
  listeners = new CopyOnWriteArrayList<>();
  lastReportedPlaybackState = STATE_IDLE;
  rendererBuildingState = RENDERER_BUILDING_STATE_IDLE;
  // Disable text initially.
  player.setSelectedTrack(TYPE_TEXT, TRACK_DISABLED);
}
 
Example #20
Source File: DemoPlayer.java    From droidkaigi2016 with Apache License 2.0 5 votes vote down vote up
public DemoPlayer(RendererBuilder rendererBuilder) {
  this.rendererBuilder = rendererBuilder;
  player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
  player.addListener(this);
  playerControl = new PlayerControl(player);
  mainHandler = new Handler();
  listeners = new CopyOnWriteArrayList<>();
  lastReportedPlaybackState = STATE_IDLE;
  rendererBuildingState = RENDERER_BUILDING_STATE_IDLE;
  // Disable text initially.
  player.setSelectedTrack(TYPE_TEXT, TRACK_DISABLED);
}
 
Example #21
Source File: ExVidPlayerImp.java    From ExVidPlayer with Apache License 2.0 5 votes vote down vote up
private void initPlayer() {
  player = ExoPlayer.Factory.newInstance(RENDERER_COUNT);
  playerControl = new PlayerControl(player);
  if (player != null) {
    rendererBuilder = getHpLibRendererBuilder();
    rendererBuilder.buildRenderers(this);
    mainHandler.postDelayed(updatePlayer, 200);
  }
}
 
Example #22
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
private void preparePlayer() {
    Log.d(TAG, "preparePlayer()");
    SampleSource sampleSource =
            new FrameworkSampleSource(this, Uri.parse(mVideo.getContentUrl()), /* headers */ null, RENDERER_COUNT);

    // Build the track renderers
    videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);
    TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

    // Setup the player
    player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
    player.addListener(this);
    player.prepare(videoRenderer, audioRenderer);
    if (mIsOnTv) {
        // This PlayerControl must stay in sync with PlaybackOverlayFragment.
        // We created methods such as PlaybackOverlayFragment.pressPlay() to request
        // that the fragment change the playback state. When the fragment receives a playback
        // request, it updates the UI and then calls a method in this activity according to
        // PlaybackOverlayFragment.OnPlayPauseClickedListener.
        playerControl = new PlayerControl(player);
    } else {
        // Build the player controls
        mediaController.setMediaPlayer(new PlayerControl(player));
        mediaController.setEnabled(true);
    }
    maybeStartPlayback();
}
 
Example #23
Source File: DemoPlayer.java    From talk-android with MIT License 5 votes vote down vote up
public DemoPlayer(RendererBuilder rendererBuilder) {
  this.rendererBuilder = rendererBuilder;
  player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, 1000, 5000);
  player.addListener(this);
  playerControl = new PlayerControl(player);
  mainHandler = new Handler();
  listeners = new CopyOnWriteArrayList<>();
  lastReportedPlaybackState = STATE_IDLE;
  rendererBuildingState = RENDERER_BUILDING_STATE_IDLE;
  // Disable text initially.
  player.setSelectedTrack(TYPE_TEXT, TRACK_DISABLED);
}
 
Example #24
Source File: DemoPlayer.java    From talk-android with MIT License 4 votes vote down vote up
public PlayerControl getPlayerControl() {
  return playerControl;
}
 
Example #25
Source File: DemoPlayer.java    From AndroidTvDemo with Apache License 2.0 4 votes vote down vote up
public PlayerControl getPlayerControl() {
  return playerControl;
}
 
Example #26
Source File: DemoPlayer.java    From ShareBox with Apache License 2.0 4 votes vote down vote up
public PlayerControl getPlayerControl() {
  return playerControl;
}
 
Example #27
Source File: PlaybackControlLayer.java    From google-media-framework-android with Apache License 2.0 4 votes vote down vote up
/**
 * Fullscreen mode will rotate to landscape mode, hide the action bar, hide the navigation bar,
 * hide the system tray, and make the video player take up the full size of the display.
 * The developer who is using this function must ensure the following:
 *
 * <p>1) Inside the android manifest, the activity that uses the video player has the attribute
 * android:configChanges="orientation".
 *
 * <p>2) Other views in the activity (or fragment) are
 * hidden (or made visible) when this method is called.
 */
public void doToggleFullscreen() {

  // If there is no callback for handling fullscreen, don't do anything.
  if (fullscreenCallback == null) {
    return;
  }
  PlayerControl playerControl = getLayerManager().getControl();
  if (playerControl == null) {
    return;
  }

  Activity activity = getLayerManager().getActivity();
  FrameLayout container = getLayerManager().getContainer();

  if (isFullscreen) {
    fullscreenCallback.onReturnFromFullscreen();
    activity.setRequestedOrientation(savedOrientation);

    // Make the status bar and navigation bar visible again.
    activity.getWindow().getDecorView().setSystemUiVisibility(0);

    container.setLayoutParams(originalContainerLayoutParams);

    fullscreenButton.setImageResource(R.drawable.ic_action_full_screen);

    isFullscreen = false;
  } else {
    fullscreenCallback.onGoToFullscreen();
    savedOrientation = activity.getResources().getConfiguration().orientation;
    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    activity.getWindow().getDecorView().setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN);

    // Whenever the status bar and navigation bar appear, we want the playback controls to
    // appear as well.
    activity.getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
        new View.OnSystemUiVisibilityChangeListener() {
          @Override
          public void onSystemUiVisibilityChange(int i) {
            // By doing a logical AND, we check if the fullscreen option is triggered (i.e. the
            // status bar is hidden). If the result of the logical AND is 0, that means that the
            // fullscreen flag is NOT triggered. This means that the status bar is showing. If
            // this is the case, then we show the playback controls as well (by calling show()).
            if ((i & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
              show();
            }
          }
        }
    );

    container.setLayoutParams(Util.getLayoutParamsBasedOnParent(container,
        ViewGroup.LayoutParams.MATCH_PARENT,
        ViewGroup.LayoutParams.MATCH_PARENT));

    fullscreenButton.setImageResource(R.drawable.ic_action_return_from_full_screen);

    isFullscreen = true;
  }
}
 
Example #28
Source File: DemoPlayer.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
public PlayerControl getPlayerControl() {
    return playerControl;
}
 
Example #29
Source File: DemoPlayer.java    From Mobilyzer with Apache License 2.0 4 votes vote down vote up
public PlayerControl getPlayerControl() {
  return playerControl;
}
 
Example #30
Source File: DemoPlayer.java    From droidkaigi2016 with Apache License 2.0 4 votes vote down vote up
public PlayerControl getPlayerControl() {
  return playerControl;
}