当前位置: 首页>>代码示例>>Java>>正文


Java DataSpec类代码示例

本文整理汇总了Java中com.google.android.exoplayer2.upstream.DataSpec的典型用法代码示例。如果您正苦于以下问题:Java DataSpec类的具体用法?Java DataSpec怎么用?Java DataSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataSpec类属于com.google.android.exoplayer2.upstream包,在下文中一共展示了DataSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: open

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
@Override
public long open(DataSpec dataSpec) throws EncryptedFileDataSourceException {
    // if we're open, we shouldn't need to open again, fast-fail
    if (mOpened) {
        return mBytesRemaining;
    }
    // #getUri is part of the contract...
    mUri = dataSpec.uri;
    // put all our throwable work in a single block, wrap the error in a custom Exception
    try {
        setupInputStream();
        skipToPosition(dataSpec);
        computeBytesRemaining(dataSpec);
    } catch (IOException e) {
        throw new EncryptedFileDataSourceException(e);
    }
    // if we made it this far, we're open
    mOpened = true;
    // notify
    if (mTransferListener != null) {
        mTransferListener.onTransferStart(this, dataSpec);
    }
    // report
    return mBytesRemaining;
}
 
开发者ID:yangchaojiang,项目名称:yjPlay,代码行数:26,代码来源:EncryptedFileDataSource.java

示例2: open

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
@Override
public long open(DataSpec dataSpec) throws IOException {
    Assertions.checkState(dataSource == null);
    String scheme = dataSpec.uri.getScheme();
    if (Util.isLocalFileUri(dataSpec.uri)) {
        if (dataSpec.uri.getPath().startsWith("/android_asset/")) {
            dataSource = getAssetDataSource();
        } else {
            dataSource = getFileDataSource();
        }
    } else if (SCHEME_ASSET.equals(scheme)) {
        dataSource = getAssetDataSource();
    } else if (SCHEME_CONTENT.equals(scheme)) {
        dataSource = getContentDataSource();
    } else if (SCHEME_RTMP.equals(scheme)) {
        dataSource = getRtmpDataSource();
    } else {
        dataSource = baseDataSource;
    }
    // Open the source and return.
    return dataSource.open(dataSpec);
}
 
开发者ID:yangchaojiang,项目名称:yjPlay,代码行数:23,代码来源:MyDefaultDataSource.java

示例3: open

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
@Override
public long open(DataSpec dataSpec) throws FileDataSourceException {
    try {
        uri = dataSpec.uri;
        file = new RandomAccessFile(dataSpec.uri.getPath(), "r");
        boolean ass = isEncrypted(file);
        if (ass) {
            file.seek(dataSpec.position + length);
        }
        bytesRemaining = dataSpec.length == C.LENGTH_UNSET ? file.length() - dataSpec.position
                : dataSpec.length;
        if (bytesRemaining < 0) {
            throw new EOFException();
        }

    } catch (IOException e) {
        throw new FileDataSourceException(e);
    }

    opened = true;
    if (listener != null) {
        listener.onTransferStart(this, dataSpec);
    }

    return bytesRemaining;
}
 
开发者ID:yangchaojiang,项目名称:yjPlay,代码行数:27,代码来源:Encrypted1FileDataSource.java

示例4: getCached

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
/**
 * Sets a {@link CachingCounters} to contain the number of bytes already downloaded and the
 * length for the content defined by a {@code dataSpec}. {@link CachingCounters#newlyCachedBytes}
 * is reset to 0.
 *
 * @param dataSpec Defines the data to be checked.
 * @param cache    A {@link Cache} which has the data.
 * @param counters The {@link CachingCounters} to update.
 */
public static void getCached(DataSpec dataSpec, Cache cache, CachingCounters counters) {
    String key = getKey(dataSpec);
    long start = dataSpec.absoluteStreamPosition;
    long left = dataSpec.length != C.LENGTH_UNSET ? dataSpec.length : cache.getContentLength(key);
    counters.contentLength = left;
    counters.alreadyCachedBytes = 0;
    counters.newlyCachedBytes = 0;
    while (left != 0) {
        long blockLength = cache.getCachedBytes(key, start,
                left != C.LENGTH_UNSET ? left : Long.MAX_VALUE);
        if (blockLength > 0) {
            counters.alreadyCachedBytes += blockLength;
        } else {
            blockLength = -blockLength;
            if (blockLength == Long.MAX_VALUE) {
                return;
            }
        }
        start += blockLength;
        left -= left == C.LENGTH_UNSET ? 0 : blockLength;
    }
}
 
开发者ID:yangchaojiang,项目名称:yjPlay,代码行数:32,代码来源:DefaultCacheUtil.java

示例5: doInBackground

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
@Override
protected List<SampleGroup> doInBackground(String... uris) {
  List<SampleGroup> result = new ArrayList<>();
  Context context = getApplicationContext();
  String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
  DataSource dataSource = new DefaultDataSource(context, null, userAgent, false);
  for (String uri : uris) {
    DataSpec dataSpec = new DataSpec(Uri.parse(uri));
    InputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
      readSampleGroups(new JsonReader(new InputStreamReader(inputStream, "UTF-8")), result);
    } catch (Exception e) {
      Log.e(TAG, "Error loading sample list: " + uri, e);
      sawError = true;
    } finally {
      Util.closeQuietly(dataSource);
    }
  }
  return result;
}
 
开发者ID:ashwanijanghu,项目名称:ExoPlayer-Offline,代码行数:21,代码来源:SampleChooserActivity.java

示例6: executePost

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
private byte[] executePost(String url, byte[] data, Map<String, String> requestProperties)
        throws IOException {
    HttpDataSource dataSource = dataSourceFactory.createDataSource();
    if (requestProperties != null) {
        for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
            dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
        }
    }
    DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
            DataSpec.FLAG_ALLOW_GZIP);
    DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
        return Util.toByteArray(inputStream);
    } finally {
        Util.closeQuietly(inputStream);
    }
}
 
开发者ID:ashwanijanghu,项目名称:ExoPlayer-Offline,代码行数:18,代码来源:CustomDrmCallback.java

示例7: maybeLoadInitData

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
private void maybeLoadInitData() throws IOException, InterruptedException {
  if (previousExtractor == extractor || initLoadCompleted || initDataSpec == null) {
    // According to spec, for packed audio, initDataSpec is expected to be null.
    return;
  }
  DataSpec initSegmentDataSpec = Util.getRemainderDataSpec(initDataSpec, initSegmentBytesLoaded);
  try {
    ExtractorInput input = new DefaultExtractorInput(initDataSource,
        initSegmentDataSpec.absoluteStreamPosition, initDataSource.open(initSegmentDataSpec));
    try {
      int result = Extractor.RESULT_CONTINUE;
      while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
        result = extractor.read(input, null);
      }
    } finally {
      initSegmentBytesLoaded = (int) (input.getPosition() - initDataSpec.absoluteStreamPosition);
    }
  } finally {
    Util.closeQuietly(dataSource);
  }
  initLoadCompleted = true;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:23,代码来源:HlsMediaChunk.java

示例8: executePost

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url,
    byte[] data, Map<String, String> requestProperties) throws IOException {
  HttpDataSource dataSource = dataSourceFactory.createDataSource();
  if (requestProperties != null) {
    for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
      dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
    }
  }
  DataSpec dataSpec = new DataSpec(Uri.parse(url), data, 0, 0, C.LENGTH_UNSET, null,
      DataSpec.FLAG_ALLOW_GZIP);
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
  try {
    return Util.toByteArray(inputStream);
  } finally {
    Util.closeQuietly(inputStream);
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:18,代码来源:HttpMediaDrmCallback.java

示例9: loadError

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
public void loadError(final DataSpec dataSpec, final int dataType, final int trackType,
    final Format trackFormat, final int trackSelectionReason, final Object trackSelectionData,
    final long mediaStartTimeUs, final long mediaEndTimeUs, final long elapsedRealtimeMs,
    final long loadDurationMs, final long bytesLoaded, final IOException error,
    final boolean wasCanceled) {
  if (listener != null) {
    handler.post(new Runnable()  {
      @Override
      public void run() {
        listener.onLoadError(dataSpec, dataType, trackType, trackFormat, trackSelectionReason,
            trackSelectionData, adjustMediaTime(mediaStartTimeUs),
            adjustMediaTime(mediaEndTimeUs), elapsedRealtimeMs, loadDurationMs, bytesLoaded,
            error, wasCanceled);
      }
    });
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:18,代码来源:AdaptiveMediaSourceEventListener.java

示例10: load

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException, InterruptedException {
  DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
  try {
    // Create and open the input.
    ExtractorInput input = new DefaultExtractorInput(dataSource,
        loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
    if (bytesLoaded == 0) {
      extractorWrapper.init(null);
    }
    // Load and decode the initialization data.
    try {
      Extractor extractor = extractorWrapper.extractor;
      int result = Extractor.RESULT_CONTINUE;
      while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
        result = extractor.read(input, null);
      }
      Assertions.checkState(result != Extractor.RESULT_SEEK);
    } finally {
      bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition);
    }
  } finally {
    Util.closeQuietly(dataSource);
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:27,代码来源:InitializationChunk.java

示例11: load

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
@Override
public void load() throws IOException, InterruptedException {
  // We always load from the beginning, so reset the sampleSize to 0.
  sampleSize = 0;
  try {
    // Create and open the input.
    dataSource.open(new DataSpec(uri));
    // Load the sample data.
    int result = 0;
    while (result != C.RESULT_END_OF_INPUT) {
      sampleSize += result;
      if (sampleData == null) {
        sampleData = new byte[INITIAL_SAMPLE_SIZE];
      } else if (sampleSize == sampleData.length) {
        sampleData = Arrays.copyOf(sampleData, sampleData.length * 2);
      }
      result = dataSource.read(sampleData, sampleSize, sampleData.length - sampleSize);
    }
  } finally {
    Util.closeQuietly(dataSource);
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:23,代码来源:SingleSampleMediaPeriod.java

示例12: open

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
@Override
public void open(DataSpec dataSpec) throws IOException {
  wrappedDataSink.open(dataSpec);
  long nonce = CryptoUtil.getFNV64Hash(dataSpec.key);
  cipher = new AesFlushingCipher(Cipher.ENCRYPT_MODE, secretKey, nonce,
      dataSpec.absoluteStreamPosition);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:8,代码来源:AesCipherDataSink.java

示例13: testUnsatisfiableRange

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
public void testUnsatisfiableRange() throws Exception {
  // Bounded request but the content length is unknown. This forces all data to be cached but not
  // the length
  assertCacheAndRead(false, true);

  // Now do an unbounded request. This will read all of the data from cache and then try to read
  // more from upstream which will cause to a 416 so CDS will store the length.
  CacheDataSource cacheDataSource = createCacheDataSource(true, true);
  assertReadDataContentLength(cacheDataSource, true, true);

  // If the user try to access off range then it should throw an IOException
  try {
    cacheDataSource = createCacheDataSource(false, false);
    cacheDataSource.open(new DataSpec(Uri.EMPTY, TEST_DATA.length, 5, KEY_1));
    fail();
  } catch (IOException e) {
    // success
  }
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:20,代码来源:CacheDataSourceTest.java

示例14: onLoadStarted

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
@SuppressWarnings({"checkstyle:ParameterNumber", "PMD.ExcessiveParameterList"}) // This implements an interface method defined by ExoPlayer
@Override
public void onLoadStarted(DataSpec dataSpec,
                          int dataType,
                          int trackType,
                          Format trackFormat,
                          int trackSelectionReason,
                          Object trackSelectionData,
                          long mediaStartTimeMs,
                          long mediaEndTimeMs,
                          long elapsedRealtimeMs) {
    for (AdaptiveMediaSourceEventListener listener : listeners) {
        listener.onLoadStarted(
                dataSpec,
                dataType,
                trackType,
                trackFormat,
                trackSelectionReason,
                trackSelectionData,
                mediaStartTimeMs,
                mediaEndTimeMs,
                elapsedRealtimeMs
        );
    }
}
 
开发者ID:novoda,项目名称:no-player,代码行数:26,代码来源:MediaSourceEventListener.java

示例15: onLoadStarted

import com.google.android.exoplayer2.upstream.DataSpec; //导入依赖的package包/类
@SuppressWarnings({"checkstyle:ParameterNumber", "PMD.ExcessiveParameterList"}) // This implements an interface method defined by ExoPlayer
@Override
public void onLoadStarted(DataSpec dataSpec,
                          int dataType,
                          int trackType,
                          Format trackFormat,
                          int trackSelectionReason,
                          Object trackSelectionData,
                          long mediaStartTimeMs,
                          long mediaEndTimeMs,
                          long elapsedRealtimeMs) {
    HashMap<String, String> callingMethodParameters = new HashMap<>();

    callingMethodParameters.put(Parameters.DATA_SPEC, String.valueOf(dataSpec));
    callingMethodParameters.put(Parameters.DATA_TYPE, String.valueOf(dataType));
    callingMethodParameters.put(Parameters.TRACK_TYPE, String.valueOf(trackType));
    callingMethodParameters.put(Parameters.TRACK_FORMAT, String.valueOf(trackFormat));
    callingMethodParameters.put(Parameters.TRACK_SELECTION_REASON, String.valueOf(trackSelectionReason));
    callingMethodParameters.put(Parameters.TRACK_SELECTION_DATA, String.valueOf(trackSelectionData));
    callingMethodParameters.put(Parameters.MEDIA_START_TIME_MS, String.valueOf(mediaStartTimeMs));
    callingMethodParameters.put(Parameters.MEDIA_END_TIME_MS, String.valueOf(mediaEndTimeMs));
    callingMethodParameters.put(Parameters.ELAPSED_REALTIME_MS, String.valueOf(elapsedRealtimeMs));

    infoListener.onNewInfo(Methods.ON_LOAD_STARTED, callingMethodParameters);
}
 
开发者ID:novoda,项目名称:no-player,代码行数:26,代码来源:MediaSourceInfoForwarder.java


注:本文中的com.google.android.exoplayer2.upstream.DataSpec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。