Java 类com.google.android.exoplayer2.ext.okhttp.OkHttpDataSourceFactory 实例源码

项目:ExoMedia    文件:App.java   
private void configureExoMedia() {
    // Registers the media sources to use the OkHttp client instead of the standard Apache one
    // Note: the OkHttpDataSourceFactory can be found in the ExoPlayer extension library `extension-okhttp`
    ExoMedia.setDataSourceFactoryProvider(new ExoMedia.DataSourceFactoryProvider() {
        @NonNull
        @Override
        public DataSource.Factory provide(@NonNull String userAgent, @Nullable TransferListener<? super DataSource> listener) {
            // Updates the network data source to use the OKHttp implementation
            DataSource.Factory upstreamFactory = new OkHttpDataSourceFactory(new OkHttpClient(), userAgent, listener);

            // Adds a cache around the upstreamFactory
            Cache cache = new SimpleCache(getCacheDir(), new LeastRecentlyUsedCacheEvictor(50 * 1024 * 1024));
            return new CacheDataSourceFactory(cache, upstreamFactory, CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
        }
    });
}
项目:AndroidAudioExample    文件:PlayerService.java   
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_DEFAULT_CHANNEL_ID, getString(R.string.notification_channel_name), NotificationManagerCompat.IMPORTANCE_DEFAULT);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(notificationChannel);

        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_MEDIA)
                .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                .build();
        audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN)
                .setOnAudioFocusChangeListener(audioFocusChangeListener)
                .setAcceptsDelayedFocusGain(false)
                .setWillPauseWhenDucked(true)
                .setAudioAttributes(audioAttributes)
                .build();
    }

    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mediaSession = new MediaSessionCompat(this, "PlayerService");
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(mediaSessionCallback);

    Context appContext = getApplicationContext();

    Intent activityIntent = new Intent(appContext, MainActivity.class);
    mediaSession.setSessionActivity(PendingIntent.getActivity(appContext, 0, activityIntent, 0));

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null, appContext, MediaButtonReceiver.class);
    mediaSession.setMediaButtonReceiver(PendingIntent.getBroadcast(appContext, 0, mediaButtonIntent, 0));

    exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl());
    exoPlayer.addListener(exoPlayerListener);
    DataSource.Factory httpDataSourceFactory = new OkHttpDataSourceFactory(new OkHttpClient(), Util.getUserAgent(this, getString(R.string.app_name)), null);
    Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100)); // 100 Mb max
    this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
    this.extractorsFactory = new DefaultExtractorsFactory();
}
项目:tumbviewer    文件:ExoPlayerInstance.java   
private ExoPlayerInstance() {
    this.context = ExpressApplication.getApplication();
    DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter();
    mainHandler = new Handler();
    defaultExtractorsFactory = new DefaultExtractorsFactory();
    mediaDataSourceFactory = new DefaultDataSourceFactory(context, defaultBandwidthMeter,
            new OkHttpDataSourceFactory(new OkHttpClient.Builder().build(),
                    Util.getUserAgent(context, "Tumbviewer"),
                    defaultBandwidthMeter, CacheControl.FORCE_NETWORK));
    TrackSelection.Factory factory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
    trackSelector = new DefaultTrackSelector(factory);
}
项目:projectBlue    文件:DiskFileCacheDataSourceFactory.java   
public DiskFileCacheDataSourceFactory(Context context, ICacheStreamSupplier cacheStreamSupplier, Library library) {
    this.cacheStreamSupplier = cacheStreamSupplier;
    httpDataSourceFactory = new OkHttpDataSourceFactory(
        okHttpClient.getObject(),
        Util.getUserAgent(context, context.getString(R.string.app_name)),
        null);

    final String authKey = library.getAuthKey();

    if (authKey != null && !authKey.isEmpty())
        httpDataSourceFactory.getDefaultRequestProperties().set("Authorization", "basic " + authKey);
}
项目:react-native-videoplayer    文件:DataSourceUtil.java   
private static HttpDataSource.Factory buildHttpDataSourceFactory(Context context, DefaultBandwidthMeter bandwidthMeter) {
    return new OkHttpDataSourceFactory(OkHttpClientProvider.getOkHttpClient(), getUserAgent(context), bandwidthMeter);
}
项目:ExoPlayer-Offline    文件:DemoApplication.java   
public HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
//    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
    return new OkHttpDataSourceFactory(okHttpClient,userAgent,bandwidthMeter);
  }