com.google.android.exoplayer2.extractor.ExtractorsFactory Java Examples

The following examples show how to use com.google.android.exoplayer2.extractor.ExtractorsFactory. 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: ExtractorMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy,
    @Nullable String customCacheKey,
    int continueLoadingCheckIntervalBytes,
    @Nullable Object tag) {
  progressiveMediaSource =
      new ProgressiveMediaSource(
          uri,
          dataSourceFactory,
          extractorsFactory,
          loadableLoadErrorHandlingPolicy,
          customCacheKey,
          continueLoadingCheckIntervalBytes,
          tag);
}
 
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: VideoPlayerComponent.java    From android-arch-components-lifecycle with Apache License 2.0 6 votes vote down vote up
private void initializePlayer() {
    if (player == null) {
        trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        player = ExoPlayerFactory.newSimpleInstance(context, trackSelector);
        player.addListener(this);
        DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(context,
                Util.getUserAgent(context, "testApp"), bandwidthMeter);

        ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
        ExtractorMediaSource videoSource = new ExtractorMediaSource(Uri.parse(videoUrl),
                dataSourceFactory, extractorsFactory, null, null);
        simpleExoPlayerView.setPlayer(player);
        player.setPlayWhenReady(true);

        boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
        if (haveResumePosition) {
            Log.d(TAG, "Have Resume position true!" + resumePosition);
            player.seekTo(resumeWindow, resumePosition);
        }

        player.prepare(videoSource, !haveResumePosition, false);

    }
}
 
Example #4
Source File: MediaPlayback21.java    From Melophile with Apache License 2.0 6 votes vote down vote up
@Override
public void startPlayer() {
  if (exoPlayer == null) {
    exoPlayer =
            ExoPlayerFactory.newSimpleInstance(
                    context, new DefaultTrackSelector(), new DefaultLoadControl());
    exoPlayer.addListener(this);
  }
  exoPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(
          context, Util.getUserAgent(context, "uamp"), null);
  ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
  MediaSource mediaSource = new ExtractorMediaSource(
          Uri.parse(currentUrl), dataSourceFactory, extractorsFactory, null, null);
  exoPlayer.prepare(mediaSource);
  configPlayer();
}
 
Example #5
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 #6
Source File: ExtractorMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    int minLoadableRetryCount,
    @Nullable String customCacheKey,
    int continueLoadingCheckIntervalBytes,
    @Nullable Object tag) {
  this.uri = uri;
  this.dataSourceFactory = dataSourceFactory;
  this.extractorsFactory = extractorsFactory;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.customCacheKey = customCacheKey;
  this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
  this.timelineDurationUs = C.TIME_UNSET;
  this.tag = tag;
}
 
Example #7
Source File: ExtractorMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the
 *     possible formats are known, pass a factory that instantiates extractors for those formats.
 *     Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache
 *     indexing. May be null.
 * @param continueLoadingCheckIntervalBytes The number of bytes that should be loaded between each
 *     invocation of {@link MediaPeriod.Callback#onContinueLoadingRequested(SequenceableLoader)}.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    int minLoadableRetryCount,
    Handler eventHandler,
    EventListener eventListener,
    String customCacheKey,
    int continueLoadingCheckIntervalBytes) {
  this(
      uri,
      dataSourceFactory,
      extractorsFactory,
      minLoadableRetryCount,
      customCacheKey,
      continueLoadingCheckIntervalBytes,
      /* tag= */ null);
  if (eventListener != null && eventHandler != null) {
    addEventListener(eventHandler, new EventListenerWrapper(eventListener));
  }
}
 
Example #8
Source File: ProgressiveMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
ProgressiveMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy,
    @Nullable String customCacheKey,
    int continueLoadingCheckIntervalBytes,
    @Nullable Object tag) {
  this.uri = uri;
  this.dataSourceFactory = dataSourceFactory;
  this.extractorsFactory = extractorsFactory;
  this.loadableLoadErrorHandlingPolicy = loadableLoadErrorHandlingPolicy;
  this.customCacheKey = customCacheKey;
  this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
  this.timelineDurationUs = C.TIME_UNSET;
  this.tag = tag;
}
 
Example #9
Source File: ExtractorMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the
 *     possible formats are known, pass a factory that instantiates extractors for those formats.
 *     Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache
 *     indexing. May be null.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    Handler eventHandler,
    EventListener eventListener,
    String customCacheKey) {
  this(
      uri,
      dataSourceFactory,
      extractorsFactory,
      eventHandler,
      eventListener,
      customCacheKey,
      DEFAULT_LOADING_CHECK_INTERVAL_BYTES);
}
 
Example #10
Source File: ExoMediaPlayer.java    From VideoDemoJava with MIT License 6 votes vote down vote up
private MediaSource getMediaSource(Uri uri){
    int contentType = Util.inferContentType(uri);
    DefaultDataSourceFactory dataSourceFactory =
            new DefaultDataSourceFactory(mAppContext,
                    Util.getUserAgent(mAppContext, mAppContext.getPackageName()), mBandwidthMeter);
    switch (contentType) {
        case C.TYPE_DASH:
            DefaultDashChunkSource.Factory factory = new DefaultDashChunkSource.Factory(dataSourceFactory);
            return new DashMediaSource(uri, dataSourceFactory, factory, null, null);
        case C.TYPE_SS:
            DefaultSsChunkSource.Factory ssFactory = new DefaultSsChunkSource.Factory(dataSourceFactory);
            return new SsMediaSource(uri, dataSourceFactory, ssFactory, null, null);
        case C.TYPE_HLS:
            return new HlsMediaSource(uri, dataSourceFactory, null, null);

        case C.TYPE_OTHER:
        default:
            // This is the MediaSource representing the media to be played.
            ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
            return new ExtractorMediaSource(uri,
                    dataSourceFactory, extractorsFactory, null, null);
    }
}
 
Example #11
Source File: ExtractorMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    int minLoadableRetryCount,
    @Nullable String customCacheKey,
    int continueLoadingCheckIntervalBytes,
    @Nullable Object tag) {
  this.uri = uri;
  this.dataSourceFactory = dataSourceFactory;
  this.extractorsFactory = extractorsFactory;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.customCacheKey = customCacheKey;
  this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
  this.timelineDurationUs = C.TIME_UNSET;
  this.tag = tag;
}
 
Example #12
Source File: ExtractorMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the
 *     possible formats are known, pass a factory that instantiates extractors for those formats.
 *     Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache
 *     indexing. May be null.
 * @param continueLoadingCheckIntervalBytes The number of bytes that should be loaded between each
 *     invocation of {@link MediaPeriod.Callback#onContinueLoadingRequested(SequenceableLoader)}.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    int minLoadableRetryCount,
    Handler eventHandler,
    EventListener eventListener,
    String customCacheKey,
    int continueLoadingCheckIntervalBytes) {
  this(
      uri,
      dataSourceFactory,
      extractorsFactory,
      minLoadableRetryCount,
      customCacheKey,
      continueLoadingCheckIntervalBytes,
      /* tag= */ null);
  if (eventListener != null && eventHandler != null) {
    addEventListener(eventHandler, new EventListenerWrapper(eventListener));
  }
}
 
Example #13
Source File: ExtractorMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy,
    @Nullable String customCacheKey,
    int continueLoadingCheckIntervalBytes,
    @Nullable Object tag) {
  progressiveMediaSource =
      new ProgressiveMediaSource(
          uri,
          dataSourceFactory,
          extractorsFactory,
          loadableLoadErrorHandlingPolicy,
          customCacheKey,
          continueLoadingCheckIntervalBytes,
          tag);
}
 
Example #14
Source File: ExtractorMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the
 *     possible formats are known, pass a factory that instantiates extractors for those formats.
 *     Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache
 *     indexing. May be null.
 * @param continueLoadingCheckIntervalBytes The number of bytes that should be loaded between each
 *     invocation of {@link MediaPeriod.Callback#onContinueLoadingRequested(SequenceableLoader)}.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    Handler eventHandler,
    EventListener eventListener,
    String customCacheKey,
    int continueLoadingCheckIntervalBytes) {
  this(
      uri,
      dataSourceFactory,
      extractorsFactory,
      new DefaultLoadErrorHandlingPolicy(),
      customCacheKey,
      continueLoadingCheckIntervalBytes,
      /* tag= */ null);
  if (eventListener != null && eventHandler != null) {
    addEventListener(eventHandler, new EventListenerWrapper(eventListener));
  }
}
 
Example #15
Source File: ExtractorMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy,
    @Nullable String customCacheKey,
    int continueLoadingCheckIntervalBytes,
    @Nullable Object tag) {
  progressiveMediaSource =
      new ProgressiveMediaSource(
          uri,
          dataSourceFactory,
          extractorsFactory,
          DrmSessionManager.getDummyDrmSessionManager(),
          loadableLoadErrorHandlingPolicy,
          customCacheKey,
          continueLoadingCheckIntervalBytes,
          tag);
}
 
Example #16
Source File: ExtractorMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the
 *     possible formats are known, pass a factory that instantiates extractors for those formats.
 *     Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache
 *     indexing. May be null.
 * @param continueLoadingCheckIntervalBytes The number of bytes that should be loaded between each
 *     invocation of {@link MediaPeriod.Callback#onContinueLoadingRequested(SequenceableLoader)}.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    @Nullable Handler eventHandler,
    @Nullable EventListener eventListener,
    @Nullable String customCacheKey,
    int continueLoadingCheckIntervalBytes) {
  this(
      uri,
      dataSourceFactory,
      extractorsFactory,
      new DefaultLoadErrorHandlingPolicy(),
      customCacheKey,
      continueLoadingCheckIntervalBytes,
      /* tag= */ null);
  if (eventListener != null && eventHandler != null) {
    addEventListener(eventHandler, new EventListenerWrapper(eventListener));
  }
}
 
Example #17
Source File: ExtractorMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the
 *     possible formats are known, pass a factory that instantiates extractors for those formats.
 *     Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache
 *     indexing. May be null.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    @Nullable Handler eventHandler,
    @Nullable EventListener eventListener,
    @Nullable String customCacheKey) {
  this(
      uri,
      dataSourceFactory,
      extractorsFactory,
      eventHandler,
      eventListener,
      customCacheKey,
      DEFAULT_LOADING_CHECK_INTERVAL_BYTES);
}
 
Example #18
Source File: ProgressiveMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
ProgressiveMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy,
    @Nullable String customCacheKey,
    int continueLoadingCheckIntervalBytes,
    @Nullable Object tag) {
  this.uri = uri;
  this.dataSourceFactory = dataSourceFactory;
  this.extractorsFactory = extractorsFactory;
  this.loadableLoadErrorHandlingPolicy = loadableLoadErrorHandlingPolicy;
  this.customCacheKey = customCacheKey;
  this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
  this.timelineDurationUs = C.TIME_UNSET;
  this.tag = tag;
}
 
Example #19
Source File: ExtractorMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the
 *     possible formats are known, pass a factory that instantiates extractors for those formats.
 *     Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache
 *     indexing. May be null.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    Handler eventHandler,
    EventListener eventListener,
    String customCacheKey) {
  this(
      uri,
      dataSourceFactory,
      extractorsFactory,
      eventHandler,
      eventListener,
      customCacheKey,
      DEFAULT_LOADING_CHECK_INTERVAL_BYTES);
}
 
Example #20
Source File: ProgressiveMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
ProgressiveMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    DrmSessionManager<?> drmSessionManager,
    LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy,
    @Nullable String customCacheKey,
    int continueLoadingCheckIntervalBytes,
    @Nullable Object tag) {
  this.uri = uri;
  this.dataSourceFactory = dataSourceFactory;
  this.extractorsFactory = extractorsFactory;
  this.drmSessionManager = drmSessionManager;
  this.loadableLoadErrorHandlingPolicy = loadableLoadErrorHandlingPolicy;
  this.customCacheKey = customCacheKey;
  this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
  this.timelineDurationUs = C.TIME_UNSET;
  this.tag = tag;
}
 
Example #21
Source File: ExtractorMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the
 *     possible formats are known, pass a factory that instantiates extractors for those formats.
 *     Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache
 *     indexing. May be null.
 * @param continueLoadingCheckIntervalBytes The number of bytes that should be loaded between each
 *     invocation of {@link MediaPeriod.Callback#onContinueLoadingRequested(SequenceableLoader)}.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    Handler eventHandler,
    EventListener eventListener,
    String customCacheKey,
    int continueLoadingCheckIntervalBytes) {
  this(
      uri,
      dataSourceFactory,
      extractorsFactory,
      new DefaultLoadErrorHandlingPolicy(),
      customCacheKey,
      continueLoadingCheckIntervalBytes,
      /* tag= */ null);
  if (eventListener != null && eventHandler != null) {
    addEventListener(eventHandler, new EventListenerWrapper(eventListener));
  }
}
 
Example #22
Source File: PlayerContainerView.java    From Anecdote with Apache License 2.0 5 votes vote down vote up
public void setVideoUrl(String url) {
    mVideoUrl = url;
    boolean needNewPlayer = mPlayer == null;
    if (needNewPlayer) {
        TrackSelection.Factory trackSelectionFactory = new FixedTrackSelection.Factory();
        mTrackSelector = new DefaultTrackSelector(trackSelectionFactory);

        mPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), mTrackSelector);
        mPlayer.addListener(this);

        mPlayerView.setPlayer(mPlayer);
        mPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
    }

    // Produces DataSource instances through which media data is loaded.
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(),
            Util.getUserAgent(getContext(), "unknown"), null);
    // Produces Extractor instances for parsing the media data.
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    // This is the MediaSource representing the media to be played.
    MediaSource videoSource = new ExtractorMediaSource(Uri.parse(url),
            dataSourceFactory, extractorsFactory, null, null);
    LoopingMediaSource loopingMediaSource = new LoopingMediaSource(videoSource);
    // Prepare the player with the source.
    mPlayer.prepare(loopingMediaSource);
    mPlayer.setVolume(0);
    mPlayerView.requestFocus();
    mPlayer.setPlayWhenReady(true); // autoplay
}
 
Example #23
Source File: ExtractorMediaSource.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the
 *     possible formats are known, pass a factory that instantiates extractors for those formats.
 *     Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache
 *     indexing. May be null.
 */
public ExtractorMediaSource(Uri uri, DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory, int minLoadableRetryCount, Handler eventHandler,
    EventListener eventListener, String customCacheKey) {
  this.uri = uri;
  this.dataSourceFactory = dataSourceFactory;
  this.extractorsFactory = extractorsFactory;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventHandler = eventHandler;
  this.eventListener = eventListener;
  this.customCacheKey = customCacheKey;
  period = new Timeline.Period();
}
 
Example #24
Source File: AudioSlidePlayer.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private MediaSource createMediaSource(@NonNull Uri uri) {
  DefaultDataSourceFactory    defaultDataSourceFactory    = new DefaultDataSourceFactory(context, "GenericUserAgent", null);
  AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(context, defaultDataSourceFactory, null);
  ExtractorsFactory           extractorsFactory           = new DefaultExtractorsFactory().setConstantBitrateSeekingEnabled(true);

  return new ExtractorMediaSource.Factory(attachmentDataSourceFactory)
          .setExtractorsFactory(extractorsFactory)
          .createMediaSource(uri);
}
 
Example #25
Source File: ProgressiveMediaSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new factory for {@link ProgressiveMediaSource}s.
 *
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for extractors used to extract media from its container.
 */
public Factory(DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) {
  this.dataSourceFactory = dataSourceFactory;
  this.extractorsFactory = extractorsFactory;
  drmSessionManager = DrmSessionManager.getDummyDrmSessionManager();
  loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
  continueLoadingCheckIntervalBytes = DEFAULT_LOADING_CHECK_INTERVAL_BYTES;
}
 
Example #26
Source File: AudioSlidePlayer.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private MediaSource createMediaSource(@NonNull Uri uri) {
  DefaultDataSourceFactory    defaultDataSourceFactory    = new DefaultDataSourceFactory(context, "GenericUserAgent", null);
  AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(context, defaultDataSourceFactory, null);
  ExtractorsFactory           extractorsFactory           = new DefaultExtractorsFactory().setConstantBitrateSeekingEnabled(true);

  return new ExtractorMediaSource.Factory(attachmentDataSourceFactory)
                                 .setExtractorsFactory(extractorsFactory)
                                 .createMediaSource(uri);
}
 
Example #27
Source File: VideoDetailsFragment.java    From Loop with Apache License 2.0 5 votes vote down vote up
private MediaSource getMediaSource(String videoUrl){
        DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
        // Produces DataSource instances through which media data is loaded.
//        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "Loop"), bandwidthMeter);
        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(LoopApplication.getInstance().getApplicationContext(), Util.getUserAgent(LoopApplication.getInstance().getApplicationContext(), "Loop"), bandwidthMeter);
        // Produces Extractor instances for parsing the media data.
        ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
        // This is the MediaSource representing the media to be played.
        MediaSource mediaSource = new ExtractorMediaSource(Uri.parse(videoUrl),
                dataSourceFactory, extractorsFactory, null, null);
        // Loops the video indefinitely.
//        LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource);
        return mediaSource;
    }
 
Example #28
Source File: ProgressiveMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new factory for {@link ProgressiveMediaSource}s.
 *
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for extractors used to extract media from its container.
 */
public Factory(DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) {
  this.dataSourceFactory = dataSourceFactory;
  this.extractorsFactory = extractorsFactory;
  loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
  continueLoadingCheckIntervalBytes = DEFAULT_LOADING_CHECK_INTERVAL_BYTES;
}
 
Example #29
Source File: ProgressiveMediaSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new factory for {@link ProgressiveMediaSource}s.
 *
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for extractors used to extract media from its container.
 */
public Factory(DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) {
  this.dataSourceFactory = dataSourceFactory;
  this.extractorsFactory = extractorsFactory;
  loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
  continueLoadingCheckIntervalBytes = DEFAULT_LOADING_CHECK_INTERVAL_BYTES;
}
 
Example #30
Source File: VideoPlayerActivity.java    From Camera-Roll-Android-App with Apache License 2.0 4 votes vote down vote up
private void initPlayer() {
    // Produces DataSource instances through which media data is loaded.
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
            Util.getUserAgent(this, getString(R.string.app_name)), null);
    // Produces Extractor instances for parsing the media data.
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    // This is the MediaSource representing the media to be played.
    MediaSource videoSource = new ExtractorMediaSource(videoUri,
            dataSourceFactory, extractorsFactory, null, null);

    DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this);

    // Create the player
    player = ExoPlayerFactory.newSimpleInstance(renderersFactory,
            new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(null)),
            new DefaultLoadControl());

    // Bind the player to the view.
    SimpleExoPlayerView simpleExoPlayerView = findViewById(R.id.simpleExoPlayerView);
    simpleExoPlayerView.setPlayer(player);

    // Prepare the player with the source.
    player.prepare(videoSource);
    player.setRepeatMode(Player.REPEAT_MODE_ONE);
    player.setPlayWhenReady(true);

    final ImageButton playPause = findViewById(R.id.play_pause);
    player.addListener(new SimpleEventListener() {
        @Override
        public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
            //update PlayPause-Button
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && showAnimations()) {
                if (player.getPlayWhenReady()) {
                    playPause.setImageResource(R.drawable.play_to_pause_avd);
                } else {
                    playPause.setImageResource(R.drawable.pause_to_play_avd);
                }

                Drawable d = playPause.getDrawable();
                if (d instanceof Animatable) {
                    ((Animatable) d).start();
                }
            } else {
                if (player.getPlayWhenReady()) {
                    playPause.setImageResource(R.drawable.ic_pause_white);
                } else {
                    playPause.setImageResource(R.drawable.ic_play_arrow_white);
                }
            }
        }
    });
}