Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
PruthiviRaj27 committed Dec 13, 2022
1 parent d5a87c5 commit 4d52321
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
4 changes: 2 additions & 2 deletions player/src/main/java/com/tpstream/player/TpStreamPlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class TpStreamPlayerImpl(val player: ExoPlayer, val context: Context) : TpStream

private fun getMediaSourceFactory(): MediaSource.Factory {
val mediaSourceFactory = DefaultMediaSourceFactory(context)
.setDataSourceFactory(VideoDownloadManager(context).build(params))
if (!videoInfo.dashUrl.equals("") && offlineVideoInfo == null) {
.setDataSourceFactory(VideoDownloadManager(context).build())
if (!(videoInfo.dashUrl == null || videoInfo.dashUrl.equals("")) && offlineVideoInfo == null) {
mediaSourceFactory.setDrmSessionManagerProvider {
DefaultDrmSessionManager.Builder().build(
CustomHttpDrmMediaCallback(context, params)
Expand Down
16 changes: 4 additions & 12 deletions player/src/main/java/com/tpstream/player/VideoDownloadManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,8 @@ class VideoDownloadManager {
return downloadManager!!
}

val params = TpInitParams.Builder()
.setOrgCode("demoveranda")
.setVideoId("o7pOsacWaJt")
.setAccessToken("143a0c71-567e-4ecd-b22d-06177228c25b")
.build()

@Synchronized
private fun initializeDownloadManger() {
Log.d("TAG", "initializeDownloadManger: ")
downloadManager = DownloadManager(
context,
getDatabaseProvider(context),
Expand All @@ -59,21 +52,20 @@ class VideoDownloadManager {
return databaseProvider
}

fun getHttpDataSourceFactory(tpInitParams: TpInitParams? = null): DataSource.Factory {
Log.d("TAG", "getHttpDataSourceFactory: ${tpInitParams?.videoId}")
fun getHttpDataSourceFactory(): DataSource.Factory {
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(VideoPlayerInterceptor(context,tpInitParams))
.addInterceptor(VideoPlayerInterceptor(context))
.build()
httpDataSourceFactory = OkHttpDataSource.Factory(okHttpClient)
return httpDataSourceFactory
}

fun build(tpInitParams: TpInitParams? = null): CacheDataSource.Factory {
fun build(): CacheDataSource.Factory {
Log.d("TAG", "build: ")
val cache = VideoDownloadManager(context).getDownloadCache()
return CacheDataSource.Factory()
.setCache(cache)
.setUpstreamDataSourceFactory(getHttpDataSourceFactory(tpInitParams))
.setUpstreamDataSourceFactory(getHttpDataSourceFactory())
.setCacheWriteDataSinkFactory(null)
.setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package com.tpstream.player

import android.content.Context
import android.util.Log
import okhttp3.Interceptor
import okhttp3.Response

class VideoPlayerInterceptor(val context: Context, private val params: TpInitParams? = null) : Interceptor {
class VideoPlayerInterceptor(val context: Context) : Interceptor {

//private lateinit var params: TpInitParams
private lateinit var params: TpInitParams

override fun intercept(chain: Interceptor.Chain): Response {
//params = Params.params

Log.d("TAG", "intercept: ")

var request = chain.request()

if(request.url.toString().contains("encryption_key")) {
params = Params.params
request = request.newBuilder()
.url( "https://${params?.orgCode}.testpress.in/api/v2.5/encryption_key/${params?.videoId}/?access_token=${params?.accessToken}")
.url( "https://${params.orgCode}.testpress.in/api/v2.5/encryption_key/${params.videoId}/?access_token=${params.accessToken}")
.build()
}
return chain.proceed(request)
Expand Down

0 comments on commit 4d52321

Please sign in to comment.