com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory Java Examples

The following examples show how to use com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory. 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: ExoPlayerView.java    From AerialDream with GNU General Public License v3.0 6 votes vote down vote up
public void setUri(Uri uri) {
    if (uri == null) {
        return;
    }

    player.stop();
    prepared = false;

    DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory("Aerial Dream");
    DataSource.Factory dataSourceFactory = cacheSize > 0
            ? new CacheDataSourceFactory(new SimpleCache(getContext().getCacheDir(), new LeastRecentlyUsedCacheEvictor(cacheSize), new ExoDatabaseProvider(getContext())), httpDataSourceFactory, 0)
            : httpDataSourceFactory;

    mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
            .createMediaSource(uri);
    player.prepare(mediaSource);
}
 
Example #2
Source File: ExoMedia.java    From QSVideoPlayer with Apache License 2.0 6 votes vote down vote up
private MediaSource buildMediaSource(Context context, Uri uri) {
    int type = getUrlType(uri.toString());
    switch (type) {
        case C.TYPE_SS:
            return new SsMediaSource(uri, new DefaultDataSourceFactory(context, null,
                    new DefaultHttpDataSourceFactory(USER_AGENT, null)),
                    new DefaultSsChunkSource.Factory(new DefaultDataSourceFactory(context, BANDWIDTH_METER,
                            new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER))), mainThreadHandler, null);
        case C.TYPE_DASH:
            return new DashMediaSource(uri, new DefaultDataSourceFactory(context, null,
                    new DefaultHttpDataSourceFactory(USER_AGENT, null)),
                    new DefaultDashChunkSource.Factory(new DefaultDataSourceFactory(context, BANDWIDTH_METER,
                            new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER))), mainThreadHandler, null);
        case C.TYPE_HLS:
            return new HlsMediaSource(uri, new DefaultDataSourceFactory(context, BANDWIDTH_METER,
                    new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER)), mainThreadHandler, null);
        case C.TYPE_OTHER:
            return new ExtractorMediaSource(uri, new DefaultDataSourceFactory(context, BANDWIDTH_METER,
                    new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER)), new DefaultExtractorsFactory(),
                    mainThreadHandler, null);
        default: {
            throw new IllegalStateException("Unsupported type: " + type);
        }
    }
}
 
Example #3
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 6 votes vote down vote up
@Override
protected final DefaultDrmSessionManager<FrameworkMediaCrypto> buildDrmSessionManager(
    final String userAgent) {
  DefaultDrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
  if (parameters.isWidevineEncrypted) {
    try {
      MediaDrmCallback drmCallback = new HttpMediaDrmCallback(parameters.widevineLicenseUrl,
          new DefaultHttpDataSourceFactory(userAgent));
      drmSessionManager = DefaultDrmSessionManager.newWidevineInstance(drmCallback, null,
          null, null);
      if (!parameters.useL1Widevine) {
        drmSessionManager.setPropertyString(SECURITY_LEVEL_PROPERTY, WIDEVINE_SECURITY_LEVEL_3);
      }
      if (offlineLicenseKeySetId != null) {
        drmSessionManager.setMode(DefaultDrmSessionManager.MODE_PLAYBACK,
            offlineLicenseKeySetId);
      }
    } catch (UnsupportedDrmException e) {
      throw new IllegalStateException(e);
    }
  }
  return drmSessionManager;
}
 
Example #4
Source File: VideoPlayer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public VideoPlayer() {
    mediaDataSourceFactory = new ExtendedDefaultDataSourceFactory(ApplicationLoader.applicationContext, BANDWIDTH_METER, new DefaultHttpDataSourceFactory("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)", BANDWIDTH_METER));

    mainHandler = new Handler();

    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
    trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    lastReportedPlaybackState = ExoPlayer.STATE_IDLE;
    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.playerDidStartPlaying);
}
 
Example #5
Source File: VideoPlayer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public VideoPlayer() {
    mediaDataSourceFactory = new ExtendedDefaultDataSourceFactory(ApplicationLoader.applicationContext, BANDWIDTH_METER, new DefaultHttpDataSourceFactory("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)", BANDWIDTH_METER));

    mainHandler = new Handler();

    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
    trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    lastReportedPlaybackState = ExoPlayer.STATE_IDLE;
    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.playerDidStartPlaying);
}
 
Example #6
Source File: MediaVideoView.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
CacheDataSourceFactory(Context context, long maxCacheSize, long maxFileSize) {
    super();
    this.context = context;
    this.maxCacheSize = maxCacheSize;
    this.maxFileSize = maxFileSize;
    String userAgent = Util.getUserAgent(context, context.getString(R.string.app_name));
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    defaultDatasourceFactory = new DefaultDataSourceFactory(this.context, bandwidthMeter,
            new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter));
}
 
Example #7
Source File: MediaSourceFactory.java    From no-player with Apache License 2.0 5 votes vote down vote up
private DefaultDataSourceFactory createDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    if (dataSourceFactory.isPresent()) {
        return new DefaultDataSourceFactory(context, bandwidthMeter, dataSourceFactory.get());
    } else {
        DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(
                userAgent,
                bandwidthMeter,
                DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
                allowCrossProtocolRedirects
        );

        return new DefaultDataSourceFactory(context, bandwidthMeter, httpDataSourceFactory);
    }
}
 
Example #8
Source File: GSYExoSubTitlePlayer.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
public MediaSource getTextSource(Uri subTitle) {
    //todo C.SELECTION_FLAG_AUTOSELECT language MimeTypes
    Format textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP, C.SELECTION_FLAG_FORCED, "en");

    DefaultHttpDataSourceFactory factory = new DefaultHttpDataSourceFactory(Util.getUserAgent(mAppContext,
            "GSYExoSubTitlePlayer"), new DefaultBandwidthMeter.Builder(mAppContext).build(),
            50000,
            50000, true);

    MediaSource textMediaSource = new SingleSampleMediaSource.Factory(new DefaultDataSourceFactory(mAppContext, null,
            factory))
            .createMediaSource(subTitle, textFormat, C.TIME_UNSET);
    return textMediaSource;

}
 
Example #9
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public TestOfflineLicenseHelper(DashHostedTestEncParameters parameters)
    throws UnsupportedDrmException {
  this.parameters = parameters;
  httpDataSourceFactory = new DefaultHttpDataSourceFactory("ExoPlayerPlaybackTests");
  offlineLicenseHelper = OfflineLicenseHelper.newWidevineInstance(
      parameters.widevineLicenseUrl, httpDataSourceFactory);
}
 
Example #10
Source File: VideoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public VideoPlayer() {
    mediaDataSourceFactory = new ExtendedDefaultDataSourceFactory(ApplicationLoader.applicationContext, BANDWIDTH_METER, new DefaultHttpDataSourceFactory("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)", BANDWIDTH_METER));

    mainHandler = new Handler();

    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
    trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    lastReportedPlaybackState = ExoPlayer.STATE_IDLE;
    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.playerDidStartPlaying);
}
 
Example #11
Source File: VideoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public VideoPlayer() {
    mediaDataSourceFactory = new ExtendedDefaultDataSourceFactory(ApplicationLoader.applicationContext, BANDWIDTH_METER, new DefaultHttpDataSourceFactory("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)", BANDWIDTH_METER));

    mainHandler = new Handler();

    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
    trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    lastReportedPlaybackState = ExoPlayer.STATE_IDLE;
    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.playerDidStartPlaying);
}
 
Example #12
Source File: VideoDialogFragment.java    From TDTChannels-APP with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_video_dialog, container, false);

    channelVideoView = rootView.findViewById(R.id.channel_video_detail_exoplayer);

    if (getArguments() != null) {
        String channelUrl = getArguments().getString(CHANNEL_KEY);
        if (getActivity() != null && getContext() != null && channelUrl != null) {
            player = new SimpleExoPlayer.Builder(getContext()).build();

            DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(
                    Util.getUserAgent(getContext(), "laquay.com.open.canalestdt"),
                    DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                    DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
                    true
            );

            dataSourceFactory = new DefaultDataSourceFactory(getContext(), httpDataSourceFactory);

            getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            loadVideo(channelUrl);
        }
    }
    return rootView;
}
 
Example #13
Source File: ExoPlayerImpl.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private DataSource.Factory buildDataSourceFactory() {
    String userAgent = Util.getUserAgent(mContext, "ExoPlayerDemo");
    DefaultDataSourceFactory upstreamFactory =
            new DefaultDataSourceFactory(mContext, new DefaultHttpDataSourceFactory(userAgent));
    return upstreamFactory;
}
 
Example #14
Source File: PlayerActivity.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "LeafPic"), bandwidthMeter);
}
 
Example #15
Source File: EvercamPlayApplication.java    From evercam-android with GNU Affero General Public License v3.0 4 votes vote down vote up
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
 
Example #16
Source File: PlayerActivity.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
private HttpDataSource.Factory buildHttpDataSourceFactory(boolean useBandwidthMeter) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "LeafPic"), useBandwidthMeter ? BANDWIDTH_METER : null);
}
 
Example #17
Source File: MediaSourceFactory.java    From CumulusTV with MIT License 4 votes vote down vote up
public static HttpDataSource.Factory buildHttpDataSourceFactory(Context context,
         DefaultBandwidthMeter bandwidthMeter) {
    String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
 
Example #18
Source File: SimpleExoPlayerInitializer.java    From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static MediaSource buildMediaSource(Uri uri, Context context) {
    String userAgent = Util.getUserAgent(context, context.getResources().getString(R.string.app_name));
    return new ExtractorMediaSource(uri,
            new DefaultHttpDataSourceFactory(userAgent),
            new DefaultExtractorsFactory(), null, null);
}
 
Example #19
Source File: VideoExoPlayer.java    From TigerVideo with Apache License 2.0 4 votes vote down vote up
private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {

        return new DefaultHttpDataSourceFactory(Util.getUserAgent(mContext, TAG), bandwidthMeter, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
    }
 
Example #20
Source File: MediaSourceCreator.java    From ExoVideoView with Apache License 2.0 4 votes vote down vote up
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
 
Example #21
Source File: LiveVideoPlayerActivity.java    From LiveVideoBroadcaster with Apache License 2.0 4 votes vote down vote up
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
  return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
 
Example #22
Source File: ExoPlayerMediaSourceBuilder.java    From PreviewSeekBar with Apache License 2.0 4 votes vote down vote up
private DataSource.Factory getHttpDataSourceFactory(boolean preview) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(context,
            "ExoPlayerDemo"), preview ? null : bandwidthMeter);
}
 
Example #23
Source File: JerryAudioHelper.java    From tysq-android with GNU General Public License v3.0 4 votes vote down vote up
public static MediaSource buildMediaSource(Uri uri) {
    return new ExtractorMediaSource.Factory(
            new DefaultHttpDataSourceFactory("exoplayer-codelab")).
            createMediaSource(uri);
}
 
Example #24
Source File: ExplorerApplication.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
	return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
 
Example #25
Source File: TubiPlayerActivity.java    From TubiPlayer with MIT License 4 votes vote down vote up
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "TubiPlayerActivity"), bandwidthMeter);
}
 
Example #26
Source File: MediaHelper.java    From TubiPlayer with MIT License 4 votes vote down vote up
public static
@NonNull
HttpDataSource.Factory buildHttpDataSourceFactory(@NonNull Context context,
        @NonNull DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(context, "TubiExoPlayer"), bandwidthMeter);
}
 
Example #27
Source File: DemoApplication.java    From TubiPlayer with MIT License 4 votes vote down vote up
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
 
Example #28
Source File: PlayerActivity.java    From alltv with MIT License 3 votes vote down vote up
private void openPlayer(String videoUrl, String videoCookie) {

        ChannelData chData = mChannels.get(mCurrentChannel);

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

        if(videoUrl == null) return;

        Uri uriLive = Uri.parse(videoUrl);

        DefaultHttpDataSourceFactory httpSourceFactory = new DefaultHttpDataSourceFactory(
                getStringById(R.string.USERAGENT), null);

        if( videoCookie != null && !videoCookie.equals("") ) {
            httpSourceFactory.getDefaultRequestProperties().set("Cookie", videoCookie);
        }

        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
                null, httpSourceFactory);

        HlsMediaSource mediaSourceLive = new HlsMediaSource.Factory(dataSourceFactory)
                .setAllowChunklessPreparation(true)
                .createMediaSource(uriLive);

        mPlayer.prepare(mediaSourceLive);

    }
 
Example #29
Source File: ExtendedDefaultDataSourceFactory.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * @param context A context.
 * @param userAgent The User-Agent string that should be used.
 * @param listener An optional listener.
 */
public ExtendedDefaultDataSourceFactory(Context context, String userAgent,
                                TransferListener listener) {
    this(context, listener, new DefaultHttpDataSourceFactory(userAgent, listener));
}
 
Example #30
Source File: ExtendedDefaultDataSourceFactory.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * @param context A context.
 * @param userAgent The User-Agent string that should be used.
 * @param listener An optional listener.
 */
public ExtendedDefaultDataSourceFactory(Context context, String userAgent,
                                TransferListener listener) {
    this(context, listener, new DefaultHttpDataSourceFactory(userAgent, listener));
}