55import android .content .Context ;
66import android .util .Log ;
77
8- import androidx .annotation .Nullable ;
8+ import androidx .annotation .NonNull ;
99
1010import com .google .android .exoplayer2 .database .StandaloneDatabaseProvider ;
1111import com .google .android .exoplayer2 .source .ProgressiveMediaSource ;
1818import com .google .android .exoplayer2 .source .smoothstreaming .SsMediaSource ;
1919import com .google .android .exoplayer2 .upstream .DataSource ;
2020import com .google .android .exoplayer2 .upstream .DefaultDataSource ;
21- import com .google .android .exoplayer2 .upstream .DefaultHttpDataSource ;
2221import com .google .android .exoplayer2 .upstream .TransferListener ;
2322import com .google .android .exoplayer2 .upstream .cache .LeastRecentlyUsedCacheEvictor ;
2423import com .google .android .exoplayer2 .upstream .cache .SimpleCache ;
2524
26- import org .schabi . newpipe . DownloaderImpl ;
25+ import org .jetbrains . annotations . Contract ;
2726import org .schabi .newpipe .extractor .services .youtube .dashmanifestcreators .YoutubeOtfDashManifestCreator ;
2827import org .schabi .newpipe .extractor .services .youtube .dashmanifestcreators .YoutubePostLiveStreamDvrDashManifestCreator ;
2928import org .schabi .newpipe .extractor .services .youtube .dashmanifestcreators .YoutubeProgressiveDashManifestCreator ;
29+ import org .schabi .newpipe .player .datasource .LoggingHttpDataSource ;
3030import org .schabi .newpipe .player .datasource .NonUriHlsDataSourceFactory ;
3131import org .schabi .newpipe .player .datasource .YoutubeHttpDataSource ;
3232
@@ -78,27 +78,32 @@ public class PlayerDataSource {
7878 private final CacheFactory ytProgressiveDashCacheDataSourceFactory ;
7979
8080
81+ private final Context context ;
82+ private final TransferListener transferListener ;
83+
84+
8185 public PlayerDataSource (final Context context ,
8286 final TransferListener transferListener ) {
83-
87+ this .context = context ;
88+ this .transferListener = transferListener ;
8489 progressiveLoadIntervalBytes = PlayerHelper .getProgressiveLoadIntervalBytes (context );
8590
8691 // make sure the static cache was created: needed by CacheFactories below
8792 instantiateCacheIfNeeded (context );
8893
89- // generic data source factories use DefaultHttpDataSource.Factory
94+ // generic data source factories use LoggingHttpDataSource.Factory, which is a wrapper
95+ // around DefaultHttpDataSource
9096 cachelessDataSourceFactory = new DefaultDataSource .Factory (context ,
91- new DefaultHttpDataSource .Factory (). setUserAgent ( DownloaderImpl . USER_AGENT ))
97+ new LoggingHttpDataSource .Factory ())
9298 .setTransferListener (transferListener );
93- cacheDataSourceFactory = new CacheFactory (context , transferListener , cache ,
94- new DefaultHttpDataSource .Factory ().setUserAgent (DownloaderImpl .USER_AGENT ));
99+ cacheDataSourceFactory = createCacheDataSourceFactory (new LoggingHttpDataSource .Factory ());
95100
96101 // YouTube-specific data source factories use getYoutubeHttpDataSourceFactory()
97- ytHlsCacheDataSourceFactory = new CacheFactory ( context , transferListener , cache ,
102+ ytHlsCacheDataSourceFactory = createCacheDataSourceFactory (
98103 getYoutubeHttpDataSourceFactory (false , false ));
99- ytDashCacheDataSourceFactory = new CacheFactory ( context , transferListener , cache ,
104+ ytDashCacheDataSourceFactory = createCacheDataSourceFactory (
100105 getYoutubeHttpDataSourceFactory (true , true ));
101- ytProgressiveDashCacheDataSourceFactory = new CacheFactory ( context , transferListener , cache ,
106+ ytProgressiveDashCacheDataSourceFactory = createCacheDataSourceFactory (
102107 getYoutubeHttpDataSourceFactory (false , true ));
103108
104109 // set the maximum size to manifest creators
@@ -108,6 +113,11 @@ public PlayerDataSource(final Context context,
108113 MAX_MANIFEST_CACHE_SIZE );
109114 }
110115
116+ @ NonNull
117+ @ Contract (value = "_ -> new" , pure = true )
118+ private CacheFactory createCacheDataSourceFactory (final DataSource .Factory wrappedFactory ) {
119+ return new CacheFactory (context , transferListener , cache , wrappedFactory );
120+ }
111121
112122 //region Live media source factories
113123 public SsMediaSource .Factory getLiveSsMediaSourceFactory () {
0 commit comments