/** * Instantiates a new Encrypted file data source factory. * * @param context the context * @param cipher the cipher * @param secretKeySpec the secret key spec * @param ivParameterSpec the iv parameter spec * @param listener the listener */ public EncryptedFileDataSourceFactory(Context context, Cipher cipher, SecretKeySpec secretKeySpec, IvParameterSpec ivParameterSpec, TransferListener<? super DataSource> listener) { mCipher = cipher; mSecretKeySpec = secretKeySpec; mIvParameterSpec = ivParameterSpec; mTransferListener = listener; String userAgent = Util.getUserAgent(context, context.getPackageName()); this.context = context.getApplicationContext(); this.baseDataSourceFactory = new DefaultDataSourceFactory(context, userAgent); }
@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; }
/** * Constructs an instance with arbitrary {@link DataSource} and {@link DataSink} instances for * reading and writing the cache. One use of this constructor is to allow data to be transformed * before it is written to disk. * * @param cache The cache. * @param upstream A {@link DataSource} for reading data not in the cache. * @param cacheReadDataSource A {@link DataSource} for reading data from the cache. * @param cacheWriteDataSink A {@link DataSink} for writing data to the cache. If null, cache is * accessed read-only. * @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE}, {@link #FLAG_IGNORE_CACHE_ON_ERROR} * and {@link #FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS}, or 0. * @param eventListener An optional {@link EventListener} to receive events. */ public CacheDataSource(Cache cache, DataSource upstream, DataSource cacheReadDataSource, DataSink cacheWriteDataSink, @Flags int flags, @Nullable EventListener eventListener) { this.cache = cache; this.cacheReadDataSource = cacheReadDataSource; this.blockOnCache = (flags & FLAG_BLOCK_ON_CACHE) != 0; this.ignoreCacheOnError = (flags & FLAG_IGNORE_CACHE_ON_ERROR) != 0; this.ignoreCacheForUnsetLengthRequests = (flags & FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS) != 0; this.upstreamDataSource = upstream; if (cacheWriteDataSink != null) { this.cacheWriteDataSource = new TeeDataSource(upstream, cacheWriteDataSink); } else { this.cacheWriteDataSource = null; } this.eventListener = eventListener; }
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { DataSource.Factory mediaDataSourceFactory = buildDataSourceFactory(true); int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri) : Util.inferContentType("." + overrideExtension); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null); case C.TYPE_HLS: return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, null); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
@Override public DataSource.Factory getDataSourceFactory() { //采用默认 return new DefaultCacheDataSourceFactory(context,100000000,"1234567887654321".getBytes(),eventListener); //自定义配置 /* LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(100000000); SimpleCache simpleCache = new SimpleCache //设置你缓存目录 (new File(context.getExternalCacheDir(), "media"), //缓存驱逐器 evictor, // 缓存文件加密,那么在使用AES / CBC的文件系统中缓存密钥将被加密 密钥必须是16字节长 "1234567887654321".getBytes()); //使用缓存数据源工厂类 return new DefaultCacheDataSourceFactory(simpleCache, //设置下载数据加载工厂类 new JDefaultDataSourceFactory(context), //设置缓存标记 0 //最大缓存文件大小,不填写 默认2m 4 * 1024 * 1024 //设置缓存监听事件 );*/ //或者 如果需要监听事件 //使用缓存数据源工厂类 /* return new CacheDataSourceFactory(simpleCache, //设置下载数据加载工厂类 new JDefaultDataSourceFactory(context), //缓存读取数据源工厂 new FileDataSourceFactory(), //缓存数据接收器的工厂 new CacheDataSinkFactory(simpleCache, CacheDataSource.DEFAULT_MAX_CACHE_FILE_SIZE), //设置缓存标记 0, //设置缓存监听事件 eventListener);*/ }
@Override public DataSource createDataSource() { if (null != mCipher) { return new MyDefaultDataSource(context, mCipher, mSecretKeySpec, mIvParameterSpec, mTransferListener, baseDataSourceFactory.createDataSource()); } else if (key != null) { return new Encrypted1FileDataSource(key, new DefaultBandwidthMeter()); } else { return new DefaultDataSource(context, new DefaultBandwidthMeter(), baseDataSourceFactory.createDataSource()); } }
/** * Closes a {@link DataSource}, suppressing any {@link IOException} that may occur. * * @param dataSource The {@link DataSource} to close. */ public static void closeQuietly(DataSource dataSource) { try { if (dataSource != null) { dataSource.close(); } } catch (IOException e) { // Ignore. } }
/*** * 初始化数据源工厂 * @return DataSource.Factory data source */ public DataSource.Factory getDataSource() { if (listener != null) { return listener.getDataSourceFactory(); } else { return new JDefaultDataSourceFactory(context); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (!isPlaying) { Handler mainHandler = new Handler(); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(MainActivity.this, trackSelector, loadControl); SimpleExoPlayerView playerView = (SimpleExoPlayerView) findViewById(R.id.videoView); playerView.setPlayer(player); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(MainActivity.this, Util.getUserAgent(MainActivity.this, "yourApplicationName")); MediaSource mediaSource = new ExtractorMediaSource(Uri.parse("https://r7---sn-3c27ln7k.googlevideo.com/videoplayback?id=6fb497d0971b8cdf&itag=22&source=picasa&begin=0&requiressl=yes&mm=30&mn=sn-3c27ln7k&ms=nxu&mv=m&nh=IgphcjAzLmticDAxKgkxMjcuMC4wLjE&pl=22&sc=yes&mime=video/mp4&lmt=1486083166327499&mt=1486135406&ip=134.249.158.189&ipbits=8&expire=1486164239&sparams=ip,ipbits,expire,id,itag,source,requiressl,mm,mn,ms,mv,nh,pl,sc,mime,lmt&signature=3BB06D8D4294F8C49B3CE910B3D6849954302BB1.02ABE00700DFCEF715E72D0EFB73B67841E659F8&key=ck2&ratebypass=yes&title=%5BAnime365%5D%20Kuzu%20no%20Honkai%20-%2004%20(t1174045)"), dataSourceFactory, new DefaultExtractorsFactory(), null, null); player.prepare(mediaSource); player.setPlayWhenReady(true); } }
@Override protected MediaSource buildSource(HostActivity host, String userAgent, TransferListener<? super DataSource> mediaTransferListener) { DataSource.Factory manifestDataSourceFactory = new DefaultDataSourceFactory(host, userAgent); DataSource.Factory mediaDataSourceFactory = new DefaultDataSourceFactory(host, userAgent, mediaTransferListener); Uri manifestUri = Uri.parse(parameters.manifestUrl); DefaultDashChunkSource.Factory chunkSourceFactory = new DefaultDashChunkSource.Factory( mediaDataSourceFactory); return new DashMediaSource(manifestUri, manifestDataSourceFactory, chunkSourceFactory, MIN_LOADABLE_RETRY_COUNT, 0 /* livePresentationDelayMs */, null, null); }
/** * Reads and discards all data specified by the {@code dataSpec}. * * @param dataSpec Defines the data to be read. * @param dataSource The {@link DataSource} to read the data from. * @param buffer The buffer to be used while downloading. * @param priorityTaskManager If not null it's used to check whether it is allowed to proceed with * caching. * @param priority The priority of this task. * @return Number of read bytes, or 0 if no data is available because the end of the opened range * has been reached. */ private static long readAndDiscard(DataSpec dataSpec, DataSource dataSource, byte[] buffer, PriorityTaskManager priorityTaskManager, int priority) throws IOException, InterruptedException { while (true) { if (priorityTaskManager != null) { // Wait for any other thread with higher priority to finish its job. priorityTaskManager.proceed(priority); } try { dataSource.open(dataSpec); long totalRead = 0; while (true) { if (Thread.interrupted()) { throw new InterruptedException(); } int read = dataSource.read(buffer, 0, buffer.length); if (read == C.RESULT_END_OF_INPUT) { return totalRead; } totalRead += read; } } catch (PriorityTaskManager.PriorityTooLowException exception) { // catch and try again } finally { Util.closeQuietly(dataSource); } } }
/** * 播放启动视频 */ private void startPlayer() { // 0. set player view playerView = (SimpleExoPlayerView) findViewById(R.id.playerView); playerView.setUseController(false); playerView.getKeepScreenOn(); playerView.setResizeMode(RESIZE_MODE_FILL); // 1. Create a default TrackSelector TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Create a default LoadControl loadControl = new DefaultLoadControl(); // 3. Create the mPlayer mPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); mPlayer.addListener(this); // 4. set player playerView.setPlayer(mPlayer); mPlayer.setPlayWhenReady(true); // 5. prepare to play File file = new File(Constants.FILE_VIDEO_FLODER, "jcode.mp4"); if (file.isFile() && file.exists()) { mUri = Uri.fromFile(file); } else { Toast.makeText(this,"文件未找到",Toast.LENGTH_SHORT).show(); return; } ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, "UserAgent"); videoSource = new ExtractorMediaSource(mUri, dataSourceFactory, extractorsFactory, null, null); // 6. ready to play mPlayer.prepare(videoSource); }
private MediaSource buildMediaSource(Uri uri) { DataSource.Factory manifestDataSourceFactory = new DefaultHttpDataSourceFactory("ua"); DashChunkSource.Factory dashChunkSourceFactory = new DefaultDashChunkSource.Factory( new DefaultHttpDataSourceFactory("ua", BANDWIDTH_METER)); return new DashMediaSource.Factory(dashChunkSourceFactory, manifestDataSourceFactory) .createMediaSource(uri); }
private MediaSource buildMediaSource(Uri uri) { DashChunkSource.Factory dashChunkSourceFactory = new DefaultDashChunkSource.Factory( new DefaultHttpDataSourceFactory("ua", BANDWIDTH_METER)); DataSource.Factory manifestDataSourceFactory = new DefaultHttpDataSourceFactory("ua"); return new DashMediaSource.Factory(dashChunkSourceFactory, manifestDataSourceFactory). createMediaSource(uri); }
public void setupMediaPlayer() { DataSource.Factory dsf = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "R/a/dio-Android-App")); ExtractorsFactory extractors = new DefaultExtractorsFactory(); MediaSource audioSource = new ExtractorMediaSource(Uri.parse(radio_url), dsf, extractors, null, null); if(sep != null) sep.prepare(audioSource); }
@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(); }
public PlayerController(Context context) { this.bandwidthMeter = new DefaultBandwidthMeter(); this.loadControl = new DefaultLoadControl(); this.extractorsFactory = new DefaultExtractorsFactory(); this.trackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); this.dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context.getApplicationContext(), TAG_NAME), (TransferListener<? super DataSource>) bandwidthMeter); this.trackSelector = new DefaultTrackSelector(trackSelectionFactory); this.player = ExoPlayerFactory.newSimpleInstance(context, this.trackSelector, this.loadControl); this.playerView = new PlayerView(context,this.player); }
private MediaSource getMediaSource(String videoUrl) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); // Produces DataSource instances through which media data is loaded. // DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "Loop"), bandwidthMeter); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(MAVApplication.getInstance().getApplicationContext(), Util.getUserAgent(MAVApplication.getInstance().getApplicationContext(), "Loop"), bandwidthMeter); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. MediaSource mediaSource = new ExtractorMediaSource(Uri.parse(videoUrl), dataSourceFactory, extractorsFactory, null, null); // Loops the video indefinitely. // LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource); return mediaSource; }
private MediaSource getMediaSource(String videoUrl) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); // Produces DataSource instances through which media data is loaded. // DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "Loop"), bandwidthMeter); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(MAVApplication.getInstance().getApplicationContext(), Util.getUserAgent(MAVApplication.getInstance().getApplicationContext(), "Loop"), bandwidthMeter); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. MediaSource mediaSource = new ExtractorMediaSource(Uri.parse(videoUrl), dataSourceFactory, extractorsFactory, null, null); // Loops the video indefinitely. // LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource); return mediaSource; }
public AttachmentDataSourceFactory(@NonNull Context context, @NonNull MasterSecret masterSecret, @NonNull DefaultDataSourceFactory defaultDataSourceFactory, @Nullable TransferListener<? super DataSource> listener) { this.context = context; this.masterSecret = masterSecret; this.defaultDataSourceFactory = defaultDataSourceFactory; this.listener = listener; }
private void initExoPlayer() { DefaultBandwidthMeter bwMeter = new DefaultBandwidthMeter(); AdaptiveTrackSelection.Factory trackFactory = new AdaptiveTrackSelection.Factory(bwMeter); DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); videoView.setPlayer(player); DataSource.Factory dsFactory = new DefaultDataSourceFactory(getBaseContext(), Util.getUserAgent(this, "Traxy"), bwMeter); ExtractorsFactory exFactory = new DefaultExtractorsFactory(); Uri mediaUri = Uri.parse(entry.getUrl()); MediaSource videoSource = new ExtractorMediaSource(mediaUri, dsFactory, exFactory, null, null); player.prepare(videoSource); }
public CustomDefaultHttpDataSourceFactory(String userAgent, TransferListener<? super DataSource> listener, boolean enableShoutcast, PlayerCallback playerCallback) { this(userAgent, listener, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, false, enableShoutcast, playerCallback); }
public CustomDefaultHttpDataSourceFactory(String userAgent, TransferListener<? super DataSource> listener, int connectTimeoutMillis, int readTimeoutMillis, boolean allowCrossProtocolRedirects, boolean enableShoutcast, PlayerCallback playerCallback) { this.userAgent = userAgent; this.listener = listener; this.connectTimeoutMillis = connectTimeoutMillis; this.readTimeoutMillis = readTimeoutMillis; this.allowCrossProtocolRedirects = allowCrossProtocolRedirects; this.enableShoutcast = enableShoutcast; this.playerCallback = playerCallback; }
/** * @param dataSource The source from which the data should be loaded. * @param dataSpec Defines the data to be loaded. * @param initDataSpec Defines the initialization data to be fed to new extractors. May be null. * @param hlsUrl The url of the playlist from which this chunk was obtained. * @param muxedCaptionFormats List of muxed caption {@link Format}s. Null if no closed caption * information is available in the master playlist. * @param trackSelectionReason See {@link #trackSelectionReason}. * @param trackSelectionData See {@link #trackSelectionData}. * @param startTimeUs The start time of the chunk in microseconds. * @param endTimeUs The end time of the chunk in microseconds. * @param chunkIndex The media sequence number of the chunk. * @param discontinuitySequenceNumber The discontinuity sequence number of the chunk. * @param isMasterTimestampSource True if the chunk can initialize the timestamp adjuster. * @param timestampAdjuster Adjuster corresponding to the provided discontinuity sequence number. * @param previousChunk The {@link HlsMediaChunk} that preceded this one. May be null. * @param encryptionKey For AES encryption chunks, the encryption key. * @param encryptionIv For AES encryption chunks, the encryption initialization vector. */ public HlsMediaChunk(DataSource dataSource, DataSpec dataSpec, DataSpec initDataSpec, HlsUrl hlsUrl, List<Format> muxedCaptionFormats, int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs, int chunkIndex, int discontinuitySequenceNumber, boolean isMasterTimestampSource, TimestampAdjuster timestampAdjuster, HlsMediaChunk previousChunk, byte[] encryptionKey, byte[] encryptionIv) { super(buildDataSource(dataSource, encryptionKey, encryptionIv), dataSpec, hlsUrl.format, trackSelectionReason, trackSelectionData, startTimeUs, endTimeUs, chunkIndex); this.discontinuitySequenceNumber = discontinuitySequenceNumber; this.initDataSpec = initDataSpec; this.hlsUrl = hlsUrl; this.muxedCaptionFormats = muxedCaptionFormats; this.isMasterTimestampSource = isMasterTimestampSource; this.timestampAdjuster = timestampAdjuster; // Note: this.dataSource and dataSource may be different. this.isEncrypted = this.dataSource instanceof Aes128DataSource; lastPathSegment = dataSpec.uri.getLastPathSegment(); isPackedAudio = lastPathSegment.endsWith(AAC_FILE_EXTENSION) || lastPathSegment.endsWith(AC3_FILE_EXTENSION) || lastPathSegment.endsWith(EC3_FILE_EXTENSION) || lastPathSegment.endsWith(MP3_FILE_EXTENSION); if (previousChunk != null) { id3Decoder = previousChunk.id3Decoder; id3Data = previousChunk.id3Data; previousExtractor = previousChunk.extractor; shouldSpliceIn = previousChunk.hlsUrl != hlsUrl; needNewExtractor = previousChunk.discontinuitySequenceNumber != discontinuitySequenceNumber || shouldSpliceIn; } else { id3Decoder = isPackedAudio ? new Id3Decoder() : null; id3Data = isPackedAudio ? new ParsableByteArray(Id3Decoder.ID3_HEADER_LENGTH) : null; previousExtractor = null; shouldSpliceIn = false; needNewExtractor = true; } initDataSource = dataSource; uid = UID_SOURCE.getAndIncrement(); }
/** * If the content is encrypted, returns an {@link Aes128DataSource} that wraps the original in * order to decrypt the loaded data. Else returns the original. */ private static DataSource buildDataSource(DataSource dataSource, byte[] encryptionKey, byte[] encryptionIv) { if (encryptionKey == null || encryptionIv == null) { return dataSource; } return new Aes128DataSource(dataSource, encryptionKey, encryptionIv); }
/** * @param dataSource The wrapped {@link DataSource}. * @param position The initial position in the stream. * @param length The length of the stream, or {@link C#LENGTH_UNSET} if it is unknown. */ public DefaultExtractorInput(DataSource dataSource, long position, long length) { this.dataSource = dataSource; this.position = position; this.streamLength = length; peekBuffer = new byte[PEEK_MIN_FREE_SPACE_AFTER_RESIZE]; }
/** * @param uri The {@link Uri} of the media stream. * @param dataSource The data source to read the media. * @param extractors The extractors to use to read the data source. * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @param sourceListener A listener to notify when the timeline has been loaded. * @param allocator An {@link Allocator} from which to obtain media buffer allocations. * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache * indexing. May be null. */ public ExtractorMediaPeriod(Uri uri, DataSource dataSource, Extractor[] extractors, int minLoadableRetryCount, Handler eventHandler, ExtractorMediaSource.EventListener eventListener, MediaSource.Listener sourceListener, Allocator allocator, String customCacheKey) { this.uri = uri; this.dataSource = dataSource; this.minLoadableRetryCount = minLoadableRetryCount; this.eventHandler = eventHandler; this.eventListener = eventListener; this.sourceListener = sourceListener; this.allocator = allocator; this.customCacheKey = customCacheKey; loader = new Loader("Loader:ExtractorMediaPeriod"); extractorHolder = new ExtractorHolder(extractors, this); loadCondition = new ConditionVariable(); maybeFinishPrepareRunnable = new Runnable() { @Override public void run() { maybeFinishPrepare(); } }; onContinueLoadingRequestedRunnable = new Runnable() { @Override public void run() { if (!released) { callback.onContinueLoadingRequested(ExtractorMediaPeriod.this); } } }; handler = new Handler(); pendingResetPositionUs = C.TIME_UNSET; sampleQueues = new SparseArray<>(); length = C.LENGTH_UNSET; }
public ExtractingLoadable(Uri uri, DataSource dataSource, ExtractorHolder extractorHolder, ConditionVariable loadCondition) { this.uri = Assertions.checkNotNull(uri); this.dataSource = Assertions.checkNotNull(dataSource); this.extractorHolder = Assertions.checkNotNull(extractorHolder); this.loadCondition = loadCondition; this.positionHolder = new PositionHolder(); this.pendingExtractorSeek = true; this.length = C.LENGTH_UNSET; }
/** * @param dataSource The source from which the data should be loaded. * @param dataSpec Defines the data to be loaded. * @param type See {@link #type}. * @param trackFormat See {@link #trackFormat}. * @param trackSelectionReason See {@link #trackSelectionReason}. * @param trackSelectionData See {@link #trackSelectionData}. * @param startTimeUs See {@link #startTimeUs}. * @param endTimeUs See {@link #endTimeUs}. */ public Chunk(DataSource dataSource, DataSpec dataSpec, int type, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs) { this.dataSource = Assertions.checkNotNull(dataSource); this.dataSpec = Assertions.checkNotNull(dataSpec); this.type = type; this.trackFormat = trackFormat; this.trackSelectionReason = trackSelectionReason; this.trackSelectionData = trackSelectionData; this.startTimeUs = startTimeUs; this.endTimeUs = endTimeUs; }
public SingleSampleMediaSource(Uri uri, DataSource.Factory dataSourceFactory, Format format, long durationUs, int minLoadableRetryCount, Handler eventHandler, EventListener eventListener, int eventSourceId) { this.uri = uri; this.dataSourceFactory = dataSourceFactory; this.format = format; this.minLoadableRetryCount = minLoadableRetryCount; this.eventHandler = eventHandler; this.eventListener = eventListener; this.eventSourceId = eventSourceId; timeline = new SinglePeriodTimeline(durationUs, true); }
/** * @param uri The {@link Uri} of the media stream. * @param dataSourceFactory A factory for {@link DataSource}s to read the media. * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the * possible formats are known, pass a factory that instantiates extractors for those formats. * Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors. * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache * indexing. May be null. */ public ExtractorMediaSource(Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, int minLoadableRetryCount, Handler eventHandler, EventListener eventListener, String customCacheKey) { this.uri = uri; this.dataSourceFactory = dataSourceFactory; this.extractorsFactory = extractorsFactory; this.minLoadableRetryCount = minLoadableRetryCount; this.eventHandler = eventHandler; this.eventListener = eventListener; this.customCacheKey = customCacheKey; period = new Timeline.Period(); }
@Override public DataSource createDataSource() { return new RawResourceDataSource(context, null); }
public static DataSource.Factory getRawDataSourceFactory(Context context) { if (rawDataSourceFactory == null) { rawDataSourceFactory = buildRawDataSourceFactory(context); } return rawDataSourceFactory; }