Beispiel #1
0
  public void onRenderers(
      String[][] trackNames, MultiTrackChunkSource[] multiTrackSources, TrackRenderer[] renderers) {
    builderCallback = null;
    // Normalize the results.
    if (trackNames == null) {
      trackNames = new String[RENDER_COUNT][];
    }

    if (multiTrackSources == null) {
      multiTrackSources = new MultiTrackChunkSource[RENDER_COUNT];
    }

    for (int i = 0; i < RENDER_COUNT; i++) {
      if (renderers[i] == null) {
        // Convert a null renderer to a dummy renderer.
        renderers[i] = new DummyTrackRenderer();
      } else if (trackNames[i] == null) {
        // We have a renderer so we must have at least one track, but the names are unknown.
        // Initialize the correct number of null track names.
        int trackCount = multiTrackSources[i] == null ? 1 : multiTrackSources[i].getTrackCount();
        trackNames[i] = new String[trackCount];
      }
    }

    // Complete preparation.
    this.videoRenderer = renderers[RENDER_VIDEO_INDEX];
    this.audioRenderer = renderers[RENDER_AUDIO_INDEX];
    this.trackNames = trackNames;
    this.multiTrackSources = multiTrackSources;
    rendererBuildingState = RenderBuildingState.BUILT;
    pushSurfaceAndVideoTrack(false);
    pushTrackSelection(RENDER_AUDIO_INDEX, true);
    pushTrackSelection(RENDER_CLOSED_CAPTION_INDEX, true);
    player.prepare(renderers);
  }
 private void onRenderers(
     RendererBuilderCallback callback,
     MediaCodecVideoTrackRenderer videoRenderer,
     MediaCodecAudioTrackRenderer audioRenderer) {
   if (mCallback != callback) {
     return;
   }
   mCallback = null;
   mVideoRenderer = videoRenderer;
   mPlayer.prepare(videoRenderer, audioRenderer);
   maybeStartPlayback();
 }
Beispiel #3
0
 /**
  * Invoked with the results from a {link RendererBuilder}.
  *
  * @param renderers Renderers indexed by {link DemoPlayer} TYPE_* constants. An individual element
  *     may be null if there do not exist tracks of the corresponding type.
  * @param bandwidthMeter Provides an estimate of the currently available bandwidth. May be null.
  */
 /* package */ void onRenderers(TrackRenderer[] renderers, BandwidthMeter bandwidthMeter) {
   for (int i = 0; i < RENDERER_COUNT; i++) {
     if (renderers[i] == null) {
       // Convert a null renderer to a dummy renderer.
       renderers[i] = new DummyTrackRenderer();
     }
   }
   // Complete preparation.
   this.videoRenderer = renderers[TYPE_VIDEO];
   this.codecCounters =
       videoRenderer instanceof MediaCodecTrackRenderer
           ? ((MediaCodecTrackRenderer) videoRenderer).codecCounters
           : renderers[TYPE_AUDIO] instanceof MediaCodecTrackRenderer
               ? ((MediaCodecTrackRenderer) renderers[TYPE_AUDIO]).codecCounters
               : null;
   this.bandwidthMeter = bandwidthMeter;
   pushSurface(false);
   player.prepare(renderers);
   rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
 }
  private void preparePlayer() {
    // TODO(cartland): Remove sample video.
    String url =
        "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/April%20Fool's%202013/Introducing%20Google%20Fiber%20to%20the%20Pole.mp4";
    mVideo.setContentUrl(url);

    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);
  }
  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) {}
        });
  }