com.google.android.exoplayer2.upstream.FileDataSource Java Examples
The following examples show how to use
com.google.android.exoplayer2.upstream.FileDataSource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DownloaderConstructorHelper.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Returns a new {@link CacheDataSource} instance. If {@code offline} is true, it can only read * data from the cache. */ public CacheDataSource buildCacheDataSource(boolean offline) { DataSource cacheReadDataSource = cacheReadDataSourceFactory != null ? cacheReadDataSourceFactory.createDataSource() : new FileDataSource(); if (offline) { return new CacheDataSource(cache, DummyDataSource.INSTANCE, cacheReadDataSource, null, CacheDataSource.FLAG_BLOCK_ON_CACHE, null); } else { DataSink cacheWriteDataSink = cacheWriteDataSinkFactory != null ? cacheWriteDataSinkFactory.createDataSink() : new CacheDataSink(cache, CacheDataSource.DEFAULT_MAX_CACHE_FILE_SIZE); DataSource upstream = upstreamDataSourceFactory.createDataSource(); upstream = priorityTaskManager == null ? upstream : new PriorityDataSource(upstream, priorityTaskManager, C.PRIORITY_DOWNLOAD); return new CacheDataSource(cache, upstream, cacheReadDataSource, cacheWriteDataSink, CacheDataSource.FLAG_BLOCK_ON_CACHE, null); } }
Example #2
Source File: DownloaderConstructorHelper.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Returns a new {@link CacheDataSource} instance. If {@code offline} is true, it can only read * data from the cache. */ public CacheDataSource buildCacheDataSource(boolean offline) { DataSource cacheReadDataSource = cacheReadDataSourceFactory != null ? cacheReadDataSourceFactory.createDataSource() : new FileDataSource(); if (offline) { return new CacheDataSource(cache, DummyDataSource.INSTANCE, cacheReadDataSource, null, CacheDataSource.FLAG_BLOCK_ON_CACHE, null); } else { DataSink cacheWriteDataSink = cacheWriteDataSinkFactory != null ? cacheWriteDataSinkFactory.createDataSink() : new CacheDataSink(cache, CacheDataSource.DEFAULT_MAX_CACHE_FILE_SIZE); DataSource upstream = upstreamDataSourceFactory.createDataSource(); upstream = priorityTaskManager == null ? upstream : new PriorityDataSource(upstream, priorityTaskManager, C.PRIORITY_DOWNLOAD); return new CacheDataSource(cache, upstream, cacheReadDataSource, cacheWriteDataSink, CacheDataSource.FLAG_BLOCK_ON_CACHE, null); } }
Example #3
Source File: MainActivity.java From ExoplayerExample with The Unlicense | 6 votes |
/** * Prepares exoplayer for audio playback from a local file * @param uri */ private void prepareExoPlayerFromFileUri(Uri uri){ exoPlayer = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector(null), new DefaultLoadControl()); exoPlayer.addListener(eventListener); DataSpec dataSpec = new DataSpec(uri); final FileDataSource fileDataSource = new FileDataSource(); try { fileDataSource.open(dataSpec); } catch (FileDataSource.FileDataSourceException e) { e.printStackTrace(); } DataSource.Factory factory = new DataSource.Factory() { @Override public DataSource createDataSource() { return fileDataSource; } }; MediaSource audioSource = new ExtractorMediaSource(fileDataSource.getUri(), factory, new DefaultExtractorsFactory(), null, null); exoPlayer.prepare(audioSource); initMediaControls(); }
Example #4
Source File: AudioPlayer.java From Tok-Android with GNU General Public License v3.0 | 5 votes |
private AudioPlayer() { mPlayer = new TokPlayer(true); mPlayer.setCycle(false); mPlayer.setOnVideoPlayerListener(new TokPlayer.VideoPlayerListenerWrapper() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playbackState == Player.STATE_ENDED) { mStatus = PlayStatus.STATUS_DONE; if (mId != null) { RxBus.publish(new ProgressEvent(mId, 0, PlayStatus.STATUS_DONE)); mId = null; } } } @Override public void onPlayerError(ExoPlaybackException error) { mStatus = PlayStatus.STATUS_ERROR; LogUtil.i(TAG, "audio play error,path:" + mUrl + ",error:" + error.getMessage()); if (error.getCause() instanceof FileDataSource.FileDataSourceException) { ToastUtils.show(R.string.file_not_exist); } else { ToastUtils.show(R.string.play_failed); } if (mId != null) { RxBus.publish(new ProgressEvent(mId, 0, PlayStatus.STATUS_ERROR)); mId = null; } } }); }
Example #5
Source File: CacheDataSource.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Constructs an instance with default {@link DataSource} and {@link DataSink} instances for * reading and writing the cache. * * @param cache The cache. * @param upstream A {@link DataSource} for reading data not in the cache. * @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. */ public CacheDataSource(Cache cache, DataSource upstream, @Flags int flags) { this( cache, upstream, new FileDataSource(), new CacheDataSink(cache, CacheDataSink.DEFAULT_FRAGMENT_SIZE), flags, /* eventListener= */ null); }
Example #6
Source File: CacheDataSourceFactory.java From MediaSDK with Apache License 2.0 | 5 votes |
/** @see CacheDataSource#CacheDataSource(Cache, DataSource, int) */ public CacheDataSourceFactory( Cache cache, DataSource.Factory upstreamFactory, @CacheDataSource.Flags int flags) { this( cache, upstreamFactory, new FileDataSource.Factory(), new CacheDataSinkFactory(cache, CacheDataSink.DEFAULT_FRAGMENT_SIZE), flags, /* eventListener= */ null); }
Example #7
Source File: ExtendedDefaultDataSource.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Constructs a new instance that delegates to a provided {@link DataSource} for URI schemes other * than file, asset and content. * * @param context A context. * @param listener An optional listener. * @param baseDataSource A {@link DataSource} to use for URI schemes other than file, asset and * content. This {@link DataSource} should normally support at least http(s). */ public ExtendedDefaultDataSource(Context context, TransferListener listener, DataSource baseDataSource) { this.baseDataSource = Assertions.checkNotNull(baseDataSource); this.fileDataSource = new FileDataSource(listener); this.encryptedFileDataSource = new EncryptedFileDataSource(listener); this.assetDataSource = new AssetDataSource(context, listener); this.contentDataSource = new ContentDataSource(context, listener); this.listener = listener; }
Example #8
Source File: ExtendedDefaultDataSource.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Constructs a new instance that delegates to a provided {@link DataSource} for URI schemes other * than file, asset and content. * * @param context A context. * @param listener An optional listener. * @param baseDataSource A {@link DataSource} to use for URI schemes other than file, asset and * content. This {@link DataSource} should normally support at least http(s). */ public ExtendedDefaultDataSource(Context context, TransferListener listener, DataSource baseDataSource) { this.baseDataSource = Assertions.checkNotNull(baseDataSource); this.fileDataSource = new FileDataSource(listener); this.encryptedFileDataSource = new EncryptedFileDataSource(listener); this.assetDataSource = new AssetDataSource(context, listener); this.contentDataSource = new ContentDataSource(context, listener); this.listener = listener; }
Example #9
Source File: MediaVideoView.java From Slide with GNU General Public License v3.0 | 5 votes |
@Override public DataSource createDataSource() { LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(maxCacheSize); SimpleCache simpleCache = new SimpleCache(new File(context.getCacheDir(), "media"), evictor); return new CacheDataSource(simpleCache, defaultDatasourceFactory.createDataSource(), new FileDataSource(), new CacheDataSink(simpleCache, maxFileSize), CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR, null); }
Example #10
Source File: CacheDataSource.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Constructs an instance with default {@link DataSource} and {@link DataSink} instances for * reading and writing the cache. * * @param cache The cache. * @param upstream A {@link DataSource} for reading data not in the cache. * @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. */ public CacheDataSource(Cache cache, DataSource upstream, @Flags int flags) { this( cache, upstream, new FileDataSource(), new CacheDataSink(cache, CacheDataSink.DEFAULT_FRAGMENT_SIZE), flags, /* eventListener= */ null); }
Example #11
Source File: CacheDataSource.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Constructs an instance with default {@link DataSource} and {@link DataSink} instances for * reading and writing the cache. * * @param cache The cache. * @param upstream A {@link DataSource} for reading data not in the cache. * @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. */ public CacheDataSource(Cache cache, DataSource upstream, @Flags int flags) { this( cache, upstream, new FileDataSource(), new CacheDataSink(cache, CacheDataSink.DEFAULT_FRAGMENT_SIZE), flags, /* eventListener= */ null); }
Example #12
Source File: ExoPlayerErrorMapperTest.java From no-player with Apache License 2.0 | 4 votes |
@Parameterized.Parameters(name = "{0} with detail {1} is mapped from {2}") public static Collection<Object[]> parameters() { return Arrays.asList( new Object[]{SOURCE, SAMPLE_QUEUE_MAPPING_ERROR, createSource(new SampleQueueMappingException("mimetype-sample"))}, new Object[]{SOURCE, READING_LOCAL_FILE_ERROR, createSource(new FileDataSource.FileDataSourceException(new IOException()))}, new Object[]{SOURCE, UNEXPECTED_LOADING_ERROR, createSource(new Loader.UnexpectedLoaderException(new Throwable()))}, new Object[]{SOURCE, LIVE_STALE_MANIFEST_AND_NEW_MANIFEST_COULD_NOT_LOAD_ERROR, createSource(new DashManifestStaleException())}, new Object[]{SOURCE, DOWNLOAD_ERROR, createSource(new DownloadException("download-exception"))}, new Object[]{SOURCE, AD_LOAD_ERROR_THEN_WILL_SKIP, createSource(AdsMediaSource.AdLoadException.createForAd(new Exception()))}, new Object[]{SOURCE, AD_GROUP_LOAD_ERROR_THEN_WILL_SKIP, createSource(AdsMediaSource.AdLoadException.createForAdGroup(new Exception(), 0))}, new Object[]{SOURCE, ALL_ADS_LOAD_ERROR_THEN_WILL_SKIP, createSource(AdsMediaSource.AdLoadException.createForAllAds(new Exception()))}, new Object[]{SOURCE, ADS_LOAD_UNEXPECTED_ERROR_THEN_WILL_SKIP, createSource(AdsMediaSource.AdLoadException.createForUnexpected(new RuntimeException()))}, new Object[]{SOURCE, MERGING_MEDIA_SOURCE_CANNOT_MERGE_ITS_SOURCES, createSource(new MergingMediaSource.IllegalMergeException(MergingMediaSource.IllegalMergeException.REASON_PERIOD_COUNT_MISMATCH))}, new Object[]{SOURCE, CLIPPING_MEDIA_SOURCE_CANNOT_CLIP_WRAPPED_SOURCE_INVALID_PERIOD_COUNT, createSource(new ClippingMediaSource.IllegalClippingException(ClippingMediaSource.IllegalClippingException.REASON_INVALID_PERIOD_COUNT))}, new Object[]{SOURCE, CLIPPING_MEDIA_SOURCE_CANNOT_CLIP_WRAPPED_SOURCE_NOT_SEEKABLE_TO_START, createSource(new ClippingMediaSource.IllegalClippingException(ClippingMediaSource.IllegalClippingException.REASON_NOT_SEEKABLE_TO_START))}, new Object[]{SOURCE, CLIPPING_MEDIA_SOURCE_CANNOT_CLIP_WRAPPED_SOURCE_INVALID_PERIOD_COUNT, createSource(new ClippingMediaSource.IllegalClippingException(ClippingMediaSource.IllegalClippingException.REASON_INVALID_PERIOD_COUNT))}, new Object[]{SOURCE, TASK_CANNOT_PROCEED_PRIORITY_TOO_LOW, createSource(new PriorityTaskManager.PriorityTooLowException(1, 2))}, new Object[]{SOURCE, PARSING_MEDIA_DATA_OR_METADATA_ERROR, createSource(new ParserException())}, new Object[]{SOURCE, CACHE_WRITING_DATA_ERROR, createSource(new Cache.CacheException("cache-exception"))}, new Object[]{SOURCE, READ_LOCAL_ASSET_ERROR, createSource(new AssetDataSource.AssetDataSourceException(new IOException()))}, new Object[]{SOURCE, DATA_POSITION_OUT_OF_RANGE_ERROR, createSource(new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE))}, new Object[]{CONNECTIVITY, HTTP_CANNOT_OPEN_ERROR, createSource(new HttpDataSource.HttpDataSourceException(new DataSpec(Uri.EMPTY, 0), HttpDataSource.HttpDataSourceException.TYPE_OPEN))}, new Object[]{CONNECTIVITY, HTTP_CANNOT_READ_ERROR, createSource(new HttpDataSource.HttpDataSourceException(new DataSpec(Uri.EMPTY, 0), HttpDataSource.HttpDataSourceException.TYPE_READ))}, new Object[]{CONNECTIVITY, HTTP_CANNOT_CLOSE_ERROR, createSource(new HttpDataSource.HttpDataSourceException(new DataSpec(Uri.EMPTY, 0), HttpDataSource.HttpDataSourceException.TYPE_CLOSE))}, new Object[]{CONNECTIVITY, READ_CONTENT_URI_ERROR, createSource(new ContentDataSource.ContentDataSourceException(new IOException()))}, new Object[]{CONNECTIVITY, READ_FROM_UDP_ERROR, createSource(new UdpDataSource.UdpDataSourceException(new IOException()))}, new Object[]{RENDERER_DECODER, AUDIO_SINK_CONFIGURATION_ERROR, createRenderer(new AudioSink.ConfigurationException("configuration-exception"))}, new Object[]{RENDERER_DECODER, AUDIO_SINK_INITIALISATION_ERROR, createRenderer(new AudioSink.InitializationException(0, 0, 0, 0))}, new Object[]{RENDERER_DECODER, AUDIO_SINK_WRITE_ERROR, createRenderer(new AudioSink.WriteException(0))}, new Object[]{RENDERER_DECODER, AUDIO_UNHANDLED_FORMAT_ERROR, createRenderer(new AudioProcessor.UnhandledFormatException(0, 0, 0))}, new Object[]{RENDERER_DECODER, AUDIO_DECODER_ERROR, createRenderer(new AudioDecoderException("audio-decoder-exception"))}, new Object[]{RENDERER_DECODER, INITIALISATION_ERROR, createRenderer(new MediaCodecRenderer.DecoderInitializationException(Format.createSampleFormat("id", "sample-mimety[e", 0), new Throwable(), true, 0))}, new Object[]{RENDERER_DECODER, DECODING_SUBTITLE_ERROR, createRenderer(new SubtitleDecoderException("metadata-decoder-exception"))}, new Object[]{DRM, UNSUPPORTED_DRM_SCHEME_ERROR, createRenderer(new UnsupportedDrmException(UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME))}, new Object[]{DRM, DRM_INSTANTIATION_ERROR, createRenderer(new UnsupportedDrmException(UnsupportedDrmException.REASON_INSTANTIATION_ERROR))}, new Object[]{DRM, DRM_SESSION_ERROR, createRenderer(new DrmSession.DrmSessionException(new Throwable()))}, new Object[]{DRM, DRM_KEYS_EXPIRED_ERROR, createRenderer(new KeysExpiredException())}, new Object[]{DRM, MEDIA_REQUIRES_DRM_SESSION_MANAGER_ERROR, createRenderer(new IllegalStateException())}, new Object[]{CONTENT_DECRYPTION, FAIL_DECRYPT_DATA_DUE_NON_PLATFORM_COMPONENT_ERROR, createRenderer(new DecryptionException(0, "decryption-exception"))}, new Object[]{UNEXPECTED, MULTIPLE_RENDERER_MEDIA_CLOCK_ENABLED_ERROR, ExoPlaybackExceptionFactory.createForUnexpected(new IllegalStateException("Multiple renderer media clocks enabled."))}, new Object[]{PlayerErrorType.UNKNOWN, DetailErrorType.UNKNOWN, ExoPlaybackExceptionFactory.createForUnexpected(new IllegalStateException("Any other exception"))} // DefaultAudioSink.InvalidAudioTrackTimestampException is private, cannot create // EGLSurfaceTexture.GlException is private, cannot create // PlaylistStuckException constructor is private, cannot create // PlaylistResetException constructor is private, cannot create // MediaCodecUtil.DecoderQueryException constructor is private, cannot create // DefaultDrmSessionManager.MissingSchemeDataException constructor is private, cannot create // Crypto Exceptions cannot be instantiated, it throws a RuntimeException("Stub!") ); }
Example #13
Source File: CacheDataSource.java From TelePlus-Android with GNU General Public License v2.0 | 3 votes |
/** * 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. * * @param cache The cache. * @param upstream A {@link DataSource} for reading data not in the cache. * @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 maxCacheFileSize The maximum size of a cache file, in bytes. If the cached data size * exceeds this value, then the data will be fragmented into multiple cache files. The * finer-grained this is the finer-grained the eviction policy can be. */ public CacheDataSource(Cache cache, DataSource upstream, @Flags int flags, long maxCacheFileSize) { this( cache, upstream, new FileDataSource(), new CacheDataSink(cache, maxCacheFileSize), flags, /* eventListener= */ null); }
Example #14
Source File: CacheDataSource.java From TelePlus-Android with GNU General Public License v2.0 | 3 votes |
/** * 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. * * @param cache The cache. * @param upstream A {@link DataSource} for reading data not in the cache. * @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 maxCacheFileSize The maximum size of a cache file, in bytes. If the cached data size * exceeds this value, then the data will be fragmented into multiple cache files. The * finer-grained this is the finer-grained the eviction policy can be. */ public CacheDataSource(Cache cache, DataSource upstream, @Flags int flags, long maxCacheFileSize) { this( cache, upstream, new FileDataSource(), new CacheDataSink(cache, maxCacheFileSize), flags, /* eventListener= */ null); }
Example #15
Source File: CacheDataSource.java From K-Sonic with MIT License | 2 votes |
/** * 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. * * @param cache The cache. * @param upstream A {@link DataSource} for reading data not in the cache. * @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE} and {@link * #FLAG_IGNORE_CACHE_ON_ERROR} or 0. * @param maxCacheFileSize The maximum size of a cache file, in bytes. If the cached data size * exceeds this value, then the data will be fragmented into multiple cache files. The * finer-grained this is the finer-grained the eviction policy can be. */ public CacheDataSource(Cache cache, DataSource upstream, @Flags int flags, long maxCacheFileSize) { this(cache, upstream, new FileDataSource(), new CacheDataSink(cache, maxCacheFileSize), flags, null); }