@Override public void buildRenderers(ExoPlayerHelper player) { Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE); // Build the video and audio renderers. Extractor webmExtractor = new WebmExtractor(); Extractor mp4Extractor = new Mp4Extractor(); DataSource dataSource = new FileDataSource(); ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, dataSource, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE, webmExtractor, mp4Extractor); MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context, sampleSource, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000, player.getMainHandler(), player, 50); MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource, MediaCodecSelector.DEFAULT, null, true, player.getMainHandler(), player); TrackRenderer textRenderer = new TextTrackRenderer(sampleSource, player, player.getMainHandler().getLooper()); // Invoke the callback. TrackRenderer[] renderers = new TrackRenderer[ExoPlayerHelper.RENDERER_COUNT]; renderers[ExoPlayerHelper.TYPE_VIDEO] = videoRenderer; renderers[ExoPlayerHelper.TYPE_AUDIO] = audioRenderer; renderers[ExoPlayerHelper.TYPE_TEXT] = textRenderer; player.onRenderers(renderers, null); }
private void loadDrmInitData(Representation representation) throws IOException { Uri initFile = representation.getInitializationUri().getUri(); FileDataSource initChunkSource = new FileDataSource(); DataSpec initDataSpec = new DataSpec(initFile); int trigger = 2; ChunkExtractorWrapper extractorWrapper = new ChunkExtractorWrapper(new FragmentedMp4Extractor()); InitializationChunk chunk = new InitializationChunk(initChunkSource, initDataSpec, trigger, format, extractorWrapper); try { chunk.load(); } catch (InterruptedException e) { Log.d(TAG, "Interrupted!", e); } if (!chunk.isLoadCanceled()) { drmInitData = chunk.getDrmInitData(); } if (drmInitData != null) { DrmInitData.SchemeInitData schemeInitData = OfflineDrmManager.getWidevineInitData(drmInitData); if (schemeInitData != null) { widevineInitData = schemeInitData.data; } } }
/** * Constructs an instance with default {@link DataSource} and {@link DataSink} instances for * reading and writing the cache. The sink is configured to fragment data such that no single * cache file is greater than maxCacheFileSize bytes. */ public CacheDataSource(Cache cache, DataSource upstream, boolean blockOnCache, boolean ignoreCacheOnError, long maxCacheFileSize) { this(cache, upstream, new FileDataSource(), new CacheDataSink(cache, maxCacheFileSize), blockOnCache, ignoreCacheOnError, null); }