public final class

OkHttpDataSourceFactory

extends HttpDataSource.BaseFactory

 java.lang.Object

androidx.media3.datasource.HttpDataSource.BaseFactory

↳androidx.media3.datasource.okhttp.OkHttpDataSourceFactory

Gradle dependencies

compile group: 'androidx.media3', name: 'media3-datasource-okhttp', version: '1.0.0-alpha03'

  • groupId: androidx.media3
  • artifactId: media3-datasource-okhttp
  • version: 1.0.0-alpha03

Artifact androidx.media3:media3-datasource-okhttp:1.0.0-alpha03 it located at Google repository (https://maven.google.com/)

Summary

Constructors
publicOkHttpDataSourceFactory(Call.Factory callFactory)

Creates an instance.

publicOkHttpDataSourceFactory(Call.Factory callFactory, java.lang.String userAgent)

Creates an instance.

publicOkHttpDataSourceFactory(Call.Factory callFactory, java.lang.String userAgent, CacheControl cacheControl)

Creates an instance.

publicOkHttpDataSourceFactory(Call.Factory callFactory, java.lang.String userAgent, TransferListener listener)

Creates an instance.

publicOkHttpDataSourceFactory(Call.Factory callFactory, java.lang.String userAgent, TransferListener listener, CacheControl cacheControl)

Creates an instance.

Methods
protected abstract HttpDataSourcecreateDataSourceInternal(HttpDataSource.RequestProperties defaultRequestProperties)

Called by HttpDataSource.BaseFactory.createDataSource() to create a HttpDataSource instance.

from HttpDataSource.BaseFactorycreateDataSource, setDefaultRequestProperties
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public OkHttpDataSourceFactory(Call.Factory callFactory)

Creates an instance.

Parameters:

callFactory: A (typically an ) for use by the sources created by the factory.

public OkHttpDataSourceFactory(Call.Factory callFactory, java.lang.String userAgent)

Creates an instance.

Parameters:

callFactory: A (typically an ) for use by the sources created by the factory.
userAgent: An optional User-Agent string.

public OkHttpDataSourceFactory(Call.Factory callFactory, java.lang.String userAgent, CacheControl cacheControl)

Creates an instance.

Parameters:

callFactory: A (typically an ) for use by the sources created by the factory.
userAgent: An optional User-Agent string.
cacheControl: An optional for setting the Cache-Control header.

public OkHttpDataSourceFactory(Call.Factory callFactory, java.lang.String userAgent, TransferListener listener)

Creates an instance.

Parameters:

callFactory: A (typically an ) for use by the sources created by the factory.
userAgent: An optional User-Agent string.
listener: An optional listener.

public OkHttpDataSourceFactory(Call.Factory callFactory, java.lang.String userAgent, TransferListener listener, CacheControl cacheControl)

Creates an instance.

Parameters:

callFactory: A (typically an ) for use by the sources created by the factory.
userAgent: An optional User-Agent string.
listener: An optional listener.
cacheControl: An optional for setting the Cache-Control header.

Methods

protected abstract HttpDataSource createDataSourceInternal(HttpDataSource.RequestProperties defaultRequestProperties)

Called by HttpDataSource.BaseFactory.createDataSource() to create a HttpDataSource instance.

Parameters:

defaultRequestProperties: The default RequestProperties to be used by the HttpDataSource instance.

Returns:

A HttpDataSource instance.

Source

/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.media3.datasource.okhttp;

import androidx.annotation.Nullable;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.HttpDataSource;
import androidx.media3.datasource.HttpDataSource.BaseFactory;
import androidx.media3.datasource.TransferListener;
import okhttp3.CacheControl;
import okhttp3.Call;

/** @deprecated Use {@link OkHttpDataSource.Factory} instead. */
@Deprecated
@UnstableApi
public final class OkHttpDataSourceFactory extends BaseFactory {

  private final Call.Factory callFactory;
  @Nullable private final String userAgent;
  @Nullable private final TransferListener listener;
  @Nullable private final CacheControl cacheControl;

  /**
   * Creates an instance.
   *
   * @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
   *     by the sources created by the factory.
   */
  public OkHttpDataSourceFactory(Call.Factory callFactory) {
    this(callFactory, /* userAgent= */ null, /* listener= */ null, /* cacheControl= */ null);
  }

  /**
   * Creates an instance.
   *
   * @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
   *     by the sources created by the factory.
   * @param userAgent An optional User-Agent string.
   */
  public OkHttpDataSourceFactory(Call.Factory callFactory, @Nullable String userAgent) {
    this(callFactory, userAgent, /* listener= */ null, /* cacheControl= */ null);
  }

  /**
   * Creates an instance.
   *
   * @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
   *     by the sources created by the factory.
   * @param userAgent An optional User-Agent string.
   * @param cacheControl An optional {@link CacheControl} for setting the Cache-Control header.
   */
  public OkHttpDataSourceFactory(
      Call.Factory callFactory, @Nullable String userAgent, @Nullable CacheControl cacheControl) {
    this(callFactory, userAgent, /* listener= */ null, cacheControl);
  }

  /**
   * Creates an instance.
   *
   * @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
   *     by the sources created by the factory.
   * @param userAgent An optional User-Agent string.
   * @param listener An optional listener.
   */
  public OkHttpDataSourceFactory(
      Call.Factory callFactory, @Nullable String userAgent, @Nullable TransferListener listener) {
    this(callFactory, userAgent, listener, /* cacheControl= */ null);
  }

  /**
   * Creates an instance.
   *
   * @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
   *     by the sources created by the factory.
   * @param userAgent An optional User-Agent string.
   * @param listener An optional listener.
   * @param cacheControl An optional {@link CacheControl} for setting the Cache-Control header.
   */
  public OkHttpDataSourceFactory(
      Call.Factory callFactory,
      @Nullable String userAgent,
      @Nullable TransferListener listener,
      @Nullable CacheControl cacheControl) {
    this.callFactory = callFactory;
    this.userAgent = userAgent;
    this.listener = listener;
    this.cacheControl = cacheControl;
  }

  // Calls deprecated constructor.
  @SuppressWarnings("deprecation")
  @Override
  protected OkHttpDataSource createDataSourceInternal(
      HttpDataSource.RequestProperties defaultRequestProperties) {
    OkHttpDataSource dataSource =
        new OkHttpDataSource(callFactory, userAgent, cacheControl, defaultRequestProperties);
    if (listener != null) {
      dataSource.addTransferListener(listener);
    }
    return dataSource;
  }
}