Search in sources :

Example 1 with DataSchemeDataSource

use of com.google.android.exoplayer2.upstream.DataSchemeDataSource in project ExoPlayer by google.

the class ImaUtil method getAdsRequestForAdTagDataSpec.

/**
 * Returns an {@link AdsRequest} based on the specified ad tag {@link DataSpec}.
 */
public static AdsRequest getAdsRequestForAdTagDataSpec(ImaFactory imaFactory, DataSpec adTagDataSpec) throws IOException {
    AdsRequest request = imaFactory.createAdsRequest();
    if (DataSchemeDataSource.SCHEME_DATA.equals(adTagDataSpec.uri.getScheme())) {
        DataSchemeDataSource dataSchemeDataSource = new DataSchemeDataSource();
        try {
            dataSchemeDataSource.open(adTagDataSpec);
            request.setAdsResponse(Util.fromUtf8Bytes(DataSourceUtil.readToEnd(dataSchemeDataSource)));
        } finally {
            dataSchemeDataSource.close();
        }
    } else {
        request.setAdTagUrl(adTagDataSpec.uri.toString());
    }
    return request;
}
Also used : AdsRequest(com.google.ads.interactivemedia.v3.api.AdsRequest) DataSchemeDataSource(com.google.android.exoplayer2.upstream.DataSchemeDataSource)

Aggregations

AdsRequest (com.google.ads.interactivemedia.v3.api.AdsRequest)1 DataSchemeDataSource (com.google.android.exoplayer2.upstream.DataSchemeDataSource)1