Java Code Examples for com.google.android.exoplayer2.upstream.DataSource#Factory

The following examples show how to use com.google.android.exoplayer2.upstream.DataSource#Factory . 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: DownloadHelper.java    From Telegram-FOSS with GNU General Public License v2.0 7 votes vote down vote up
/**
 * Utility method to create a MediaSource which only contains the tracks defined in {@code
 * downloadRequest}.
 *
 * @param downloadRequest A {@link DownloadRequest}.
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @return A MediaSource which only contains the tracks defined in {@code downloadRequest}.
 */
public static MediaSource createMediaSource(
    DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory) {
  MediaSourceFactory factory;
  switch (downloadRequest.type) {
    case DownloadRequest.TYPE_DASH:
      factory = DASH_FACTORY;
      break;
    case DownloadRequest.TYPE_SS:
      factory = SS_FACTORY;
      break;
    case DownloadRequest.TYPE_HLS:
      factory = HLS_FACTORY;
      break;
    case DownloadRequest.TYPE_PROGRESSIVE:
      return new ProgressiveMediaSource.Factory(dataSourceFactory)
          .createMediaSource(downloadRequest.uri);
    default:
      throw new IllegalStateException("Unsupported type: " + downloadRequest.type);
  }
  return factory.createMediaSource(
      downloadRequest.uri, dataSourceFactory, downloadRequest.streamKeys);
}
 
Example 2
Source File: SingleSampleMediaSource.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 The factory from which the {@link DataSource} to read the media will
 *     be obtained.
 * @param format The {@link Format} associated with the output track.
 * @param durationUs The duration of the media stream in microseconds.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public SingleSampleMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    Format format,
    long durationUs,
    int minLoadableRetryCount) {
  this(
      uri,
      dataSourceFactory,
      format,
      durationUs,
      new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount),
      /* treatLoadErrorsAsEndOfStream= */ false,
      /* tag= */ null);
}
 
Example 3
Source File: DownloadHelper.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link DownloadHelper} for SmoothStreaming streams.
 *
 * @param uri A manifest {@link Uri}.
 * @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest.
 * @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are
 *     selected.
 * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers created by
 *     {@code renderersFactory}.
 * @param trackSelectorParameters {@link DefaultTrackSelector.Parameters} for selecting tracks for
 *     downloading.
 * @return A {@link DownloadHelper} for SmoothStreaming streams.
 * @throws IllegalStateException If the SmoothStreaming module is missing.
 */
public static DownloadHelper forSmoothStreaming(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    RenderersFactory renderersFactory,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    DefaultTrackSelector.Parameters trackSelectorParameters) {
  return new DownloadHelper(
      DownloadRequest.TYPE_SS,
      uri,
      /* cacheKey= */ null,
      createMediaSourceInternal(
          SS_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null),
      trackSelectorParameters,
      Util.getRendererCapabilities(renderersFactory, drmSessionManager));
}
 
Example 4
Source File: DownloaderConstructorHelper.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamFactory A {@link DataSource.Factory} for creating {@link DataSource}s for
 *     downloading data.
 * @param cacheReadDataSourceFactory A {@link DataSource.Factory} for creating {@link DataSource}s
 *     for reading data from the cache. If null then a {@link FileDataSource.Factory} will be
 *     used.
 * @param cacheWriteDataSinkFactory A {@link DataSink.Factory} for creating {@link DataSource}s
 *     for writing data to the cache. If null then a {@link CacheDataSinkFactory} will be used.
 * @param priorityTaskManager A {@link PriorityTaskManager} to use when downloading. If non-null,
 *     downloaders will register as tasks with priority {@link C#PRIORITY_DOWNLOAD} whilst
 *     downloading.
 */
public DownloaderConstructorHelper(
    Cache cache,
    DataSource.Factory upstreamFactory,
    @Nullable DataSource.Factory cacheReadDataSourceFactory,
    @Nullable DataSink.Factory cacheWriteDataSinkFactory,
    @Nullable PriorityTaskManager priorityTaskManager) {
  this(
      cache,
      upstreamFactory,
      cacheReadDataSourceFactory,
      cacheWriteDataSinkFactory,
      priorityTaskManager,
      /* cacheKeyFactory= */ null);
}
 
Example 5
Source File: StoryAudioPlayer.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
public void updateCursor(Cursor cursor, int mimeTypeColumn, int uriColumn) {
    if (this.cursor != null) {
        this.cursor.close();
    }
    this.cursor = cursor;
    if (this.cursor != null) {
        getOrCreatePlayer();
        for (int index = (currentPosition + 1); index < this.cursor.getCount(); index++) {
            cursor.moveToPosition(index);
            String mime = cursor.getString(mimeTypeColumn);
            Uri uri = Uri.parse(cursor.getString(uriColumn));

            DataSpec dataSpec = new DataSpec(uri);
            final VideoViewActivity.InputStreamDataSource inputStreamDataSource = new VideoViewActivity.InputStreamDataSource(context, dataSpec);
            try {
                inputStreamDataSource.open(dataSpec);
            } catch (IOException e) {
                e.printStackTrace();
            }

            DataSource.Factory factory = new DataSource.Factory() {
                @Override
                public DataSource createDataSource() {
                    return inputStreamDataSource;
                }
            };
            MediaSource mediaSource = new ExtractorMediaSource(inputStreamDataSource.getUri(),
                    factory, new DefaultExtractorsFactory(), null, null);
            Log.d("AudioPlayer", "Add media source " + uri);
            concatenatingMediaSource.addMediaSource(mediaSource);
        }
        currentPosition = this.cursor.getCount() - 1;
    }

    player.setPlayWhenReady(true);
    player.prepare(concatenatingMediaSource);

}
 
Example 6
Source File: DownloadManager.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link DownloadManager}.
 *
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamDataSourceFactory A {@link DataSource.Factory} for creating data sources for
 *     downloading upstream data.
 * @param actionSaveFile File to save active actions.
 * @param deserializers Used to deserialize {@link DownloadAction}s. If empty, {@link
 *     DownloadAction#getDefaultDeserializers()} is used instead.
 */
public DownloadManager(
    Cache cache,
    DataSource.Factory upstreamDataSourceFactory,
    File actionSaveFile,
    Deserializer... deserializers) {
  this(
      new DownloaderConstructorHelper(cache, upstreamDataSourceFactory),
      actionSaveFile,
      deserializers);
}
 
Example 7
Source File: DownloadHelper.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** @deprecated Use {@link #forHls(Context, Uri, Factory, RenderersFactory)} */
@Deprecated
public static DownloadHelper forHls(
    Uri uri, DataSource.Factory dataSourceFactory, RenderersFactory renderersFactory) {
  return forHls(
      uri,
      dataSourceFactory,
      renderersFactory,
      /* drmSessionManager= */ null,
      DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_VIEWPORT);
}
 
Example 8
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 9
Source File: DataSourceUtil.java    From react-native-video with MIT License 4 votes vote down vote up
public static void setRawDataSourceFactory(DataSource.Factory factory) {
    DataSourceUtil.rawDataSourceFactory = factory;
}
 
Example 10
Source File: LiveVideoPlayerActivity.java    From LiveVideoBroadcaster with Apache License 2.0 4 votes vote down vote up
public DataSource.Factory buildDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
  return new DefaultDataSourceFactory(this, bandwidthMeter,
          buildHttpDataSourceFactory(bandwidthMeter));
}
 
Example 11
Source File: MediaSourceCreator.java    From ExoVideoView with Apache License 2.0 4 votes vote down vote up
private DataSource.Factory buildDataSourceFactory(boolean useBandwidthMeter) {
    return buildDataSourceFactory(useBandwidthMeter ? BANDWIDTH_METER : null);
}
 
Example 12
Source File: DashDownloadHelper.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public DashDownloadHelper(Uri uri, DataSource.Factory manifestDataSourceFactory) {
  this.uri = uri;
  this.manifestDataSourceFactory = manifestDataSourceFactory;
}
 
Example 13
Source File: PlayerActivity.java    From exoplayer-intro with Apache License 2.0 4 votes vote down vote up
private MediaSource buildMediaSource(Uri uri) {
  DataSource.Factory dataSourceFactory =
    new DefaultDataSourceFactory(this, "exoplayer-codelab");
  DashMediaSource.Factory mediaSourceFactory = new DashMediaSource.Factory(dataSourceFactory);
  return mediaSourceFactory.createMediaSource(uri);
}
 
Example 14
Source File: DashMediaSource.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private DashMediaSource(
    @Nullable DashManifest manifest,
    @Nullable Uri manifestUri,
    @Nullable DataSource.Factory manifestDataSourceFactory,
    @Nullable ParsingLoadable.Parser<? extends DashManifest> manifestParser,
    DashChunkSource.Factory chunkSourceFactory,
    CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
    DrmSessionManager<?> drmSessionManager,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy,
    long livePresentationDelayMs,
    boolean livePresentationDelayOverridesManifest,
    @Nullable Object tag) {
  this.initialManifestUri = manifestUri;
  this.manifest = manifest;
  this.manifestUri = manifestUri;
  this.manifestDataSourceFactory = manifestDataSourceFactory;
  this.manifestParser = manifestParser;
  this.chunkSourceFactory = chunkSourceFactory;
  this.drmSessionManager = drmSessionManager;
  this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
  this.livePresentationDelayMs = livePresentationDelayMs;
  this.livePresentationDelayOverridesManifest = livePresentationDelayOverridesManifest;
  this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
  this.tag = tag;
  sideloadedManifest = manifest != null;
  manifestEventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null);
  manifestUriLock = new Object();
  periodsById = new SparseArray<>();
  playerEmsgCallback = new DefaultPlayerEmsgCallback();
  expiredManifestPublishTimeUs = C.TIME_UNSET;
  if (sideloadedManifest) {
    Assertions.checkState(!manifest.dynamic);
    manifestCallback = null;
    refreshManifestRunnable = null;
    simulateManifestRefreshRunnable = null;
    manifestLoadErrorThrower = new LoaderErrorThrower.Dummy();
  } else {
    manifestCallback = new ManifestCallback();
    manifestLoadErrorThrower = new ManifestLoadErrorThrower();
    refreshManifestRunnable = this::startLoadingManifest;
    simulateManifestRefreshRunnable = () -> processManifest(false);
  }
}
 
Example 15
Source File: PlayerActivity.java    From alltv with MIT License 4 votes vote down vote up
private void openPlayer(String videoUrl) {

        ChannelData chData = mChannels.get(mCurrentChannel);

        if ( chData.isAudioChannel() ) {
            Picasso.get().load(chData.getStillImageUrl()).into(this);
        }

        if(videoUrl == null) return;

        Uri uriLive = Uri.parse(videoUrl);

        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
                getStringById(R.string.USERAGENT));
        HlsMediaSource mediaSourceLive = new HlsMediaSource.Factory(dataSourceFactory)
                .setAllowChunklessPreparation(true)
                .createMediaSource(uriLive);

        mPlayer.prepare(mediaSourceLive);

    }
 
Example 16
Source File: ExtractorMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 3 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.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    Handler eventHandler,
    EventListener eventListener) {
  this(uri, dataSourceFactory, extractorsFactory, eventHandler, eventListener, null);
}
 
Example 17
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a new factory for {@link DashMediaSource}s.
 *
 * @param dataSourceFactory A factory for {@link DataSource} instances that will be used to load
 *     manifest and media data.
 */
public Factory(DataSource.Factory dataSourceFactory) {
  this(new DefaultDashChunkSource.Factory(dataSourceFactory), dataSourceFactory);
}
 
Example 18
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a new factory for {@link SsMediaSource}s.
 *
 * @param dataSourceFactory A factory for {@link DataSource} instances that will be used to load
 *     manifest and media data.
 */
public Factory(DataSource.Factory dataSourceFactory) {
  this(new DefaultSsChunkSource.Factory(dataSourceFactory), dataSourceFactory);
}
 
Example 19
Source File: HlsMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a new factory for {@link HlsMediaSource}s.
 *
 * @param dataSourceFactory A data source factory that will be wrapped by a {@link
 *     DefaultHlsDataSourceFactory} to create {@link DataSource}s for manifests, segments and
 *     keys.
 */
public Factory(DataSource.Factory dataSourceFactory) {
  this(new DefaultHlsDataSourceFactory(dataSourceFactory));
}
 
Example 20
Source File: LiveVideoPlayerActivity.java    From LiveVideoBroadcaster with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a new DataSource factory.
 *
 * @param useBandwidthMeter Whether to set {@link #BANDWIDTH_METER} as a listener to the new
 *     DataSource factory.
 * @return A new DataSource factory.
 */
private DataSource.Factory buildDataSourceFactory(boolean useBandwidthMeter) {
  return buildDataSourceFactory(useBandwidthMeter ? BANDWIDTH_METER : null);
}