com.google.android.exoplayer2.LoadControl Java Examples

The following examples show how to use com.google.android.exoplayer2.LoadControl. 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: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
public ExoMediaPlayer(@NonNull Context context) {
    this.context = context;

    bufferRepeater.setRepeaterDelay(BUFFER_REPEAT_DELAY);
    bufferRepeater.setRepeatListener(new BufferRepeatListener());

    mainHandler = new Handler();

    ComponentListener componentListener = new ComponentListener();
    RendererProvider rendererProvider = new RendererProvider(context, mainHandler, componentListener, componentListener, componentListener, componentListener);
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = generateDrmSessionManager();
    rendererProvider.setDrmSessionManager(drmSessionManager);

    renderers = rendererProvider.generate();

    adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);

    LoadControl loadControl = ExoMedia.Data.loadControl != null ? ExoMedia.Data.loadControl : new DefaultLoadControl();
    player = ExoPlayerFactory.newInstance(renderers.toArray(new Renderer[renderers.size()]), trackSelector, loadControl);
    player.addListener(this);
    analyticsCollector = new AnalyticsCollector.Factory().createAnalyticsCollector(player, Clock.DEFAULT);
    player.addListener(analyticsCollector);
    setupDamSessionManagerAnalytics(drmSessionManager);
}
 
Example #2
Source File: VideoPlayer.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
private void setExoViewSource(@NonNull VideoSlide videoSource, boolean autoplay)
    throws IOException
{
  BandwidthMeter         bandwidthMeter             = new DefaultBandwidthMeter();
  TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
  TrackSelector          trackSelector              = new DefaultTrackSelector(videoTrackSelectionFactory);
  LoadControl            loadControl                = new DefaultLoadControl();

  exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl);
  exoPlayer.addListener(new ExoPlayerListener(window));
  //noinspection ConstantConditions
  exoView.setPlayer(exoPlayer);

  DefaultDataSourceFactory    defaultDataSourceFactory    = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null);
  AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), defaultDataSourceFactory, null);
  ExtractorsFactory           extractorsFactory           = new DefaultExtractorsFactory();

  MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null);

  exoPlayer.prepare(mediaSource);
  exoPlayer.setPlayWhenReady(autoplay);
}
 
Example #3
Source File: MainActivity.java    From ExoplayerExample with The Unlicense 6 votes vote down vote up
/**
 * Prepares exoplayer for audio playback from a remote URL audiofile. Should work with most
 * popular audiofile types (.mp3, .m4a,...)
 * @param uri Provide a Uri in a form of Uri.parse("http://blabla.bleble.com/blublu.mp3)
 */
private void prepareExoPlayerFromURL(Uri uri){

    TrackSelector trackSelector = new DefaultTrackSelector();

    LoadControl loadControl = new DefaultLoadControl();

    exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);

    DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayer2example"), null);
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    MediaSource audioSource = new ExtractorMediaSource(uri, dataSourceFactory, extractorsFactory, null, null);
    exoPlayer.addListener(eventListener);

    exoPlayer.prepare(audioSource);
    initMediaControls();
}
 
Example #4
Source File: AudioSlidePlayer.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
public void requestDuration() {
  try {
    LoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE).createDefaultLoadControl();
    durationCalculator = ExoPlayerFactory.newSimpleInstance(context, new DefaultRenderersFactory(context), new DefaultTrackSelector(), loadControl);
    durationCalculator.setPlayWhenReady(false);
    durationCalculator.addListener(new Player.EventListener() {
      @Override
      public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
        if (playbackState == Player.STATE_READY) {
            Util.runOnMain(() -> {
              Log.d(TAG, "request duration " + durationCalculator.getDuration());
              getListener().onReceivedDuration(Long.valueOf(durationCalculator.getDuration()).intValue());
              durationCalculator.release();
              durationCalculator.removeListener(this);
              durationCalculator = null;
            });
        }
      }
    });
    durationCalculator.prepare(createMediaSource(slide.getUri()));
  } catch (Exception e) {
      Log.w(TAG, e);
      getListener().onReceivedDuration(0);
  }
}
 
Example #5
Source File: VideoPlayer.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public VideoPlayer(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    inflate(context, R.layout.video_player_layout, this);
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    LoadControl loadControl = new DefaultLoadControl();
    RenderersFactory renderersFactory = new DefaultRenderersFactory(getContext());
    this.exoView = findViewById(R.id.video_view);
    this.exoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl);
    this.exoPlayer.addListener(new ExoPlayerListener());
    if (exoView != null) {
        exoView.setPlayer(exoPlayer);
    }
    this.audioView = findViewById(R.id.audio_btn);

    this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    //        VolumeChangeObserver.INSTANCE.registerReceiver();
    //        VolumeChangeObserver.INSTANCE.addCallback(observerCallback);
    audioVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    exoPlayer.setVolume(audioVolume);

    if (audioVolume == 0) {
        audioView.setImageResource(R.drawable.common_video_player_mute_icon);
        isMuted = true;
    }
}
 
Example #6
Source File: DefaultPlayer.java    From ARVI with Apache License 2.0 5 votes vote down vote up
public DefaultPlayer(@NonNull Context context,
                     @NonNull RenderersFactory renderersFactory,
                     @NonNull TrackSelector trackSelector,
                     @NonNull LoadControl loadControl,
                     @Nullable BandwidthMeter bandwidthMeter) {
    this(
        context,
        renderersFactory,
        trackSelector,
        loadControl,
        bandwidthMeter,
        null
    );
}
 
Example #7
Source File: DefaultPlayer.java    From ARVI with Apache License 2.0 5 votes vote down vote up
public DefaultPlayer(@NonNull Context context,
                     @NonNull RenderersFactory renderersFactory,
                     @NonNull TrackSelector trackSelector,
                     @NonNull LoadControl loadControl,
                     @Nullable BandwidthMeter bandwidthMeter,
                     @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
    this.context = checkNonNull(context).getApplicationContext();
    this.eventHandler = new PlayerEventListenerRegistry();
    this.renderersFactory = checkNonNull(renderersFactory);
    this.trackSelector = checkNonNull(trackSelector);
    this.loadControl = checkNonNull(loadControl);
    this.bandwidthMeter = bandwidthMeter;
    this.drmSessionManager = drmSessionManager;
}
 
Example #8
Source File: VideoDetailsFragment.java    From Loop with Apache License 2.0 5 votes vote down vote up
private void setUpExoPlayer(){
    // Create a default TrackSelector
    TrackSelector trackSelector = createTrackSelector();

    // Create a default LoadControl
    LoadControl loadControl = new DefaultLoadControl();

    // Create the player
    exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl);
    resumeLocalVideo();

    exoPlayer.addListener(exoPlayerEventListener);
}
 
Example #9
Source File: IjkExo2MediaPlayer.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
public LoadControl getLoadControl() {
    return mLoadControl;
}
 
Example #10
Source File: BufferSizeAdaptationBuilder.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Builds player components for buffer size based track adaptation.
 *
 * @return A pair of a {@link TrackSelection.Factory} and a {@link LoadControl}, which should be
 *     used to construct the player.
 */
public Pair<TrackSelection.Factory, LoadControl> buildPlayerComponents() {
  Assertions.checkArgument(hysteresisBufferMs < maxBufferMs - minBufferMs);
  Assertions.checkState(!buildCalled);
  buildCalled = true;

  DefaultLoadControl.Builder loadControlBuilder =
      new DefaultLoadControl.Builder()
          .setTargetBufferBytes(/* targetBufferBytes = */ Integer.MAX_VALUE)
          .setBufferDurationsMs(
              /* minBufferMs= */ maxBufferMs,
              maxBufferMs,
              bufferForPlaybackMs,
              bufferForPlaybackAfterRebufferMs);
  if (allocator != null) {
    loadControlBuilder.setAllocator(allocator);
  }

  TrackSelection.Factory trackSelectionFactory =
      new TrackSelection.Factory() {
        @Override
        public @NullableType TrackSelection[] createTrackSelections(
            @NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
          return TrackSelectionUtil.createTrackSelectionsForDefinitions(
              definitions,
              definition ->
                  new BufferSizeAdaptiveTrackSelection(
                      definition.group,
                      definition.tracks,
                      bandwidthMeter,
                      minBufferMs,
                      maxBufferMs,
                      hysteresisBufferMs,
                      startUpBandwidthFraction,
                      startUpMinBufferForQualityIncreaseMs,
                      dynamicFormatFilter,
                      clock));
        }
      };

  return Pair.create(trackSelectionFactory, loadControlBuilder.createDefaultLoadControl());
}
 
Example #11
Source File: BufferSizeAdaptationBuilder.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Builds player components for buffer size based track adaptation.
 *
 * @return A pair of a {@link TrackSelection.Factory} and a {@link LoadControl}, which should be
 *     used to construct the player.
 */
public Pair<TrackSelection.Factory, LoadControl> buildPlayerComponents() {
  Assertions.checkArgument(hysteresisBufferMs < maxBufferMs - minBufferMs);
  Assertions.checkState(!buildCalled);
  buildCalled = true;

  DefaultLoadControl.Builder loadControlBuilder =
      new DefaultLoadControl.Builder()
          .setTargetBufferBytes(/* targetBufferBytes = */ Integer.MAX_VALUE)
          .setBufferDurationsMs(
              /* minBufferMs= */ maxBufferMs,
              maxBufferMs,
              bufferForPlaybackMs,
              bufferForPlaybackAfterRebufferMs);
  if (allocator != null) {
    loadControlBuilder.setAllocator(allocator);
  }

  TrackSelection.Factory trackSelectionFactory =
      new TrackSelection.Factory() {
        @Override
        public @NullableType TrackSelection[] createTrackSelections(
            @NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
          return TrackSelectionUtil.createTrackSelectionsForDefinitions(
              definitions,
              definition ->
                  new BufferSizeAdaptiveTrackSelection(
                      definition.group,
                      definition.tracks,
                      bandwidthMeter,
                      minBufferMs,
                      maxBufferMs,
                      hysteresisBufferMs,
                      startUpBandwidthFraction,
                      startUpMinBufferForQualityIncreaseMs,
                      dynamicFormatFilter,
                      clock));
        }
      };

  return Pair.create(trackSelectionFactory, loadControlBuilder.createDefaultLoadControl());
}
 
Example #12
Source File: CumulusTvPlayer.java    From CumulusTV with MIT License 4 votes vote down vote up
public CumulusTvPlayer(Context context, TrackSelector trackSelector, LoadControl loadControl) {
    mSimpleExoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector, loadControl);
    mContext = context;
    mSimpleExoPlayer.addListener(this);
    mSimpleExoPlayer.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT);
}
 
Example #13
Source File: QueuedExoPlayer.java    From Jockey with Apache License 2.0 4 votes vote down vote up
public QueuedExoPlayer(Context context) {
    mContext = context;
    mState = ExoPlayerState.IDLE;
    mQueue = Collections.emptyList();

    mSourceFactory = new DefaultDataSourceFactory(mContext, USER_AGENT);
    mExtractorsFactory = new DefaultExtractorsFactory();

    RenderersFactory renderersFactory = new DefaultRenderersFactory(mContext);
    TrackSelector trackSelector = new DefaultTrackSelector(new FixedTrackSelection.Factory());
    LoadControl loadControl = new DefaultLoadControl();
    SimpleExoPlayer baseInstance = ExoPlayerFactory.newSimpleInstance(
            renderersFactory, trackSelector, loadControl);
    mExoPlayer = new EqualizedExoPlayer(context, baseInstance);

    mExoPlayer.addListener(new Player.EventListener() {
        @Override
        public void onLoadingChanged(boolean isLoading) {
            Timber.i("onLoadingChanged (%b)", isLoading);
        }

        @Override
        public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
            Timber.i("onPlayerStateChanged");
            QueuedExoPlayer.this.onPlayerStateChanged(playbackState);
        }

        @Override
        public void onRepeatModeChanged(int repeatMode) {
            Timber.i("onRepeatModeChanged (%d)", repeatMode);
        }

        @Override
        public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
            Timber.i("onShuffleModeEnabledChanged (%b)", shuffleModeEnabled);
        }

        @Override
        public void onTimelineChanged(Timeline timeline, Object manifest) {
            Timber.i("onTimelineChanged");
            dispatchDurationUpdateIfNeeded();
        }

        @Override
        public void onTracksChanged(TrackGroupArray trackGroups,
                                    TrackSelectionArray trackSelections) {
            Timber.i("onTracksChanged");
        }

        @Override
        public void onPlayerError(ExoPlaybackException error) {
            Timber.i("onPlayerError");
            QueuedExoPlayer.this.onPlayerError(error);
        }

        @Override
        public void onPositionDiscontinuity(int reason) {
            Timber.i("onPositionDiscontinuity");
            QueuedExoPlayer.this.onPositionDiscontinuity(reason);
        }

        @Override
        public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
            Timber.i("onPlaybackParametersChanged");
        }

        @Override
        public void onSeekProcessed() {
            Timber.i("okSeekProcessed");
        }
    });
}
 
Example #14
Source File: AudioSlidePlayer.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
private void play(final double progress, boolean earpiece) throws IOException {
  if (this.mediaPlayer != null) {
    return;
  }

  if (slide.getUri() == null) {
    throw new IOException("Slide has no URI!");
  }

  LoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE).createDefaultLoadControl();
  this.mediaPlayer           = ExoPlayerFactory.newSimpleInstance(context, new DefaultRenderersFactory(context), new DefaultTrackSelector(), loadControl);
  this.startTime             = System.currentTimeMillis();

  mediaPlayer.prepare(createMediaSource(slide.getUri()));
  mediaPlayer.setPlayWhenReady(true);
  mediaPlayer.setAudioAttributes(new AudioAttributes.Builder()
          .setContentType(earpiece ? C.CONTENT_TYPE_SPEECH : C.CONTENT_TYPE_MUSIC)
          .setUsage(earpiece ? C.USAGE_VOICE_COMMUNICATION : C.USAGE_MEDIA)
          .build());
  mediaPlayer.addListener(new Player.EventListener() {

    boolean started = false;

    @Override
    public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
      Log.d(TAG, "onPlayerStateChanged(" + playWhenReady + ", " + playbackState + ")");
      switch (playbackState) {
        case Player.STATE_READY:

          Log.i(TAG, "onPrepared() " + mediaPlayer.getBufferedPercentage() + "% buffered");
          synchronized (AudioSlidePlayer.this) {
            if (mediaPlayer == null) return;
            Log.d(TAG, "DURATION: " + mediaPlayer.getDuration());

            if (started) {
              Log.d(TAG, "Already started. Ignoring.");
              return;
            }

            started = true;

            if (progress > 0) {
              mediaPlayer.seekTo((long) (mediaPlayer.getDuration() * progress));
            }

            setPlaying(AudioSlidePlayer.this);
          }

          notifyOnStart();
          progressEventHandler.sendEmptyMessage(0);
          break;

        case Player.STATE_ENDED:
          Log.i(TAG, "onComplete");
          synchronized (AudioSlidePlayer.this) {
            getListener().onReceivedDuration(Long.valueOf(mediaPlayer.getDuration()).intValue());
            mediaPlayer = null;
          }

          notifyOnStop();
          progressEventHandler.removeMessages(0);
      }
    }

    @Override
    public void onPlayerError(ExoPlaybackException error) {
      Log.w(TAG, "MediaPlayer Error: " + error);

      Toast.makeText(context, R.string.error, Toast.LENGTH_SHORT).show();

      synchronized (AudioSlidePlayer.this) {
        mediaPlayer = null;
      }

      notifyOnStop();
      progressEventHandler.removeMessages(0);
    }
  });
}
 
Example #15
Source File: IjkExo2MediaPlayer.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
public void setLoadControl(LoadControl loadControl) {
    this.mLoadControl = loadControl;
}
 
Example #16
Source File: AudioSlidePlayer.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private void play(final double progress, boolean earpiece) throws IOException {
  if (this.mediaPlayer != null) {
    return;
  }

  if (slide.getUri() == null) {
    throw new IOException("Slide has no URI!");
  }

  LoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE).createDefaultLoadControl();
  this.mediaPlayer           = ExoPlayerFactory.newSimpleInstance(context, new DefaultRenderersFactory(context), new DefaultTrackSelector(), loadControl);
  this.startTime             = System.currentTimeMillis();

  mediaPlayer.prepare(createMediaSource(slide.getUri()));
  mediaPlayer.setPlayWhenReady(true);
  mediaPlayer.setAudioAttributes(new AudioAttributes.Builder()
                                                    .setContentType(earpiece ? C.CONTENT_TYPE_SPEECH : C.CONTENT_TYPE_MUSIC)
                                                    .setUsage(earpiece ? C.USAGE_VOICE_COMMUNICATION : C.USAGE_MEDIA)
                                                    .build());
  mediaPlayer.addListener(new Player.EventListener() {

    boolean started = false;

    @Override
    public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
      Log.d(TAG, "onPlayerStateChanged(" + playWhenReady + ", " + playbackState + ")");
      switch (playbackState) {
        case Player.STATE_READY:
          Log.i(TAG, "onPrepared() " + mediaPlayer.getBufferedPercentage() + "% buffered");
          synchronized (AudioSlidePlayer.this) {
            if (mediaPlayer == null) return;

            if (started) {
              Log.d(TAG, "Already started. Ignoring.");
              return;
            }

            started = true;

            if (progress > 0) {
              mediaPlayer.seekTo((long) (mediaPlayer.getDuration() * progress));
            }

            sensorManager.registerListener(AudioSlidePlayer.this, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL);

            setPlaying(AudioSlidePlayer.this);
          }

          notifyOnStart();
          progressEventHandler.sendEmptyMessage(0);
          break;

        case Player.STATE_ENDED:
          Log.i(TAG, "onComplete");
          synchronized (AudioSlidePlayer.this) {
            mediaPlayer = null;

            sensorManager.unregisterListener(AudioSlidePlayer.this);

            if (wakeLock != null && wakeLock.isHeld()) {
              if (Build.VERSION.SDK_INT >= 21) {
                wakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY);
              }
            }
          }

          notifyOnStop();
          progressEventHandler.removeMessages(0);
      }
    }

    @Override
    public void onPlayerError(ExoPlaybackException error) {
      Log.w(TAG, "MediaPlayer Error: " + error);

      Toast.makeText(context, R.string.AudioSlidePlayer_error_playing_audio, Toast.LENGTH_SHORT).show();

      synchronized (AudioSlidePlayer.this) {
        mediaPlayer = null;

        sensorManager.unregisterListener(AudioSlidePlayer.this);

        if (wakeLock != null && wakeLock.isHeld()) {
          if (Build.VERSION.SDK_INT >= 21) {
            wakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY);
          }
        }
      }

      notifyOnStop();
      progressEventHandler.removeMessages(0);
    }
  });
}
 
Example #17
Source File: MainActivity.java    From WhatsAppStatusSaver with Apache License 2.0 4 votes vote down vote up
public void showImagePopup(Point p, final String uri) {
        Activity context = MainActivity.this;
        //COMPLETED solving video problem

        final Dialog dialog = new Dialog(context);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.image_popup_layout);
        dialog.show();
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.copyFrom(dialog.getWindow().getAttributes());
        dialog.getWindow().setAttributes(lp);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog.getWindow().setDimAmount(0);


        // Getting a reference to Close button, and close the popup when clicked.
        FloatingActionButton close = (FloatingActionButton) dialog.findViewById(R.id.close_image_popup_button);
        ImageView statusImage = (ImageView) dialog.findViewById(R.id.full_status_image_view);
        final SimpleExoPlayerView simpleExoPlayerView = dialog.findViewById(R.id.full_status_video_view);
        final SimpleExoPlayer player;
        if (uri.endsWith(".jpg")) {
            GlideApp.with(context).load(uri).into(statusImage);
        } else if (uri.endsWith(".mp4")) {
            statusImage.setVisibility(View.GONE);
            simpleExoPlayerView.setVisibility(View.VISIBLE);
            Uri myUri = Uri.parse(uri); // initialize Uri here

            // 1. Create a default TrackSelector
            BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
            TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
            TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

// 2. Create a default LoadControl
            LoadControl loadControl = new DefaultLoadControl();

// 3. Create the player
            player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);

//Set media controller
            simpleExoPlayerView.setUseController(true);
            simpleExoPlayerView.requestFocus();

// Bind the player to the view.
            simpleExoPlayerView.setPlayer(player);

            //Measures bandwidth during playback. Can be null if not required.
            DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter();
//Produces DataSource instances through which media data is loaded.
            DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.
                    getUserAgent(this, "exoplayer2example"), bandwidthMeterA);
//Produces Extractor instances for parsing the media data.
            ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();

            MediaSource videoSource = new ExtractorMediaSource(myUri, dataSourceFactory, extractorsFactory, null, null);
            player.prepare(videoSource);
            player.setPlayWhenReady(true); //run file/link when ready to play.
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    player.release();
                }
            });

        }
        close.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
//                popup.dismiss();
                dialog.cancel();
            }
        });
    }
 
Example #18
Source File: DebugSimpleExoPlayer.java    From ExoPlayer-Offline with Apache License 2.0 4 votes vote down vote up
public DebugSimpleExoPlayer(Context context, TrackSelector trackSelector,
    LoadControl loadControl, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  super(context, trackSelector, loadControl, drmSessionManager,
      SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF, 0);
}
 
Example #19
Source File: ExoVideoView.java    From DKVideoPlayer with Apache License 2.0 4 votes vote down vote up
public void setLoadControl(LoadControl loadControl) {
    mLoadControl = loadControl;
}
 
Example #20
Source File: ExoMediaPlayer.java    From DKVideoPlayer with Apache License 2.0 4 votes vote down vote up
public void setLoadControl(LoadControl loadControl) {
    mLoadControl = loadControl;
}
 
Example #21
Source File: DefaultPlayer.java    From ARVI with Apache License 2.0 4 votes vote down vote up
public DefaultPlayer(@NonNull Context context,
                     @NonNull RenderersFactory renderersFactory,
                     @NonNull TrackSelector trackSelector,
                     @NonNull LoadControl loadControl) {
    this(
        context,
        renderersFactory,
        trackSelector,
        loadControl,
        null
    );
}
 
Example #22
Source File: BufferSizeAdaptationBuilder.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * Builds player components for buffer size based track adaptation.
 *
 * @return A pair of a {@link TrackSelection.Factory} and a {@link LoadControl}, which should be
 *     used to construct the player.
 */
public Pair<TrackSelection.Factory, LoadControl> buildPlayerComponents() {
  Assertions.checkArgument(hysteresisBufferMs < maxBufferMs - minBufferMs);
  Assertions.checkState(!buildCalled);
  buildCalled = true;

  DefaultLoadControl.Builder loadControlBuilder =
      new DefaultLoadControl.Builder()
          .setTargetBufferBytes(/* targetBufferBytes = */ Integer.MAX_VALUE)
          .setBufferDurationsMs(
              /* minBufferMs= */ maxBufferMs,
              maxBufferMs,
              bufferForPlaybackMs,
              bufferForPlaybackAfterRebufferMs);
  if (allocator != null) {
    loadControlBuilder.setAllocator(allocator);
  }

  TrackSelection.Factory trackSelectionFactory =
      new TrackSelection.Factory() {
        @Override
        public @NullableType TrackSelection[] createTrackSelections(
            @NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
          return TrackSelectionUtil.createTrackSelectionsForDefinitions(
              definitions,
              definition ->
                  new BufferSizeAdaptiveTrackSelection(
                      definition.group,
                      definition.tracks,
                      bandwidthMeter,
                      minBufferMs,
                      maxBufferMs,
                      hysteresisBufferMs,
                      startUpBandwidthFraction,
                      startUpMinBufferForQualityIncreaseMs,
                      dynamicFormatFilter,
                      clock));
        }
      };

  return Pair.create(trackSelectionFactory, loadControlBuilder.createDefaultLoadControl());
}
 
Example #23
Source File: VideoPlayer.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public void setVideoSource(@NonNull VideoSlide videoSource, boolean autoplay) {
  Context                 context                    = getContext();
  DefaultRenderersFactory renderersFactory           = new DefaultRenderersFactory(context);
  TrackSelection.Factory  videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
  TrackSelector           trackSelector              = new DefaultTrackSelector(videoTrackSelectionFactory);
  LoadControl             loadControl                = new DefaultLoadControl();

  exoPlayer = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector, loadControl);
  exoPlayer.addListener(new ExoPlayerListener(window, playerStateCallback));
  exoPlayer.addListener(new Player.DefaultEventListener() {
    @Override
    public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
      if (playerCallback != null) {
        switch (playbackState) {
          case Player.STATE_READY:
            if (playWhenReady) playerCallback.onPlaying();
            break;
          case Player.STATE_ENDED:
            playerCallback.onStopped();
            break;
        }
      }
    }
  });
  exoView.setPlayer(exoPlayer);
  exoControls.setPlayer(exoPlayer);

  DefaultDataSourceFactory    defaultDataSourceFactory    = new DefaultDataSourceFactory(context, "GenericUserAgent", null);
  AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(context, defaultDataSourceFactory, null);
  ExtractorsFactory           extractorsFactory           = new DefaultExtractorsFactory();

  createMediaSource = () -> new ExtractorMediaSource.Factory(attachmentDataSourceFactory)
                                                    .setExtractorsFactory(extractorsFactory)
                                                    .createMediaSource(videoSource.getUri());

  exoPlayer.prepare(createMediaSource.create());
  exoPlayer.setPlayWhenReady(autoplay);
}
 
Example #24
Source File: ExoMedia.java    From ExoMedia with Apache License 2.0 2 votes vote down vote up
/**
 * Specifies the {@link LoadControl} to use when building the {@link com.google.android.exoplayer2.ExoPlayer} instance
 * used in the {@link com.devbrackets.android.exomedia.ui.widget.VideoView} and {@link AudioPlayer}. This allows the
 * buffering amounts to be modified to better suit your needs which can be easily specified by using an instance of
 * {@link com.google.android.exoplayer2.DefaultLoadControl}. When the <code>loadControl</code> is <code>null</code>
 * the default instance of the {@link com.google.android.exoplayer2.DefaultLoadControl} will be used. This will only
 * take effect for any instances created <i>after</i> this was set.
 *
 * @param loadControl The {@link LoadControl} to use for any new {@link com.google.android.exoplayer2.ExoPlayer} instances
 */
public static void setLoadControl(@Nullable LoadControl loadControl) {
    Data.loadControl = loadControl;
}