Skip to content

Commit

Permalink
tweaks on exoplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
kl3jvi committed May 20, 2022
1 parent 5e1830c commit c2a3da3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.google.android.exoplayer2.ui.TrackSelectionDialogBuilder
import com.google.android.exoplayer2.upstream.DataSource
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
import com.google.android.exoplayer2.util.Util
import com.google.common.net.HttpHeaders.USER_AGENT
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.ktx.Firebase
Expand All @@ -36,7 +35,6 @@ import com.kl3jvi.animity.data.model.ui_models.EpisodeModel
import com.kl3jvi.animity.databinding.ActivityPlayerBinding
import com.kl3jvi.animity.utils.Constants
import com.kl3jvi.animity.utils.Constants.Companion.REFERER
import com.kl3jvi.animity.utils.Constants.Companion.getDataSourceFactory
import com.kl3jvi.animity.utils.Constants.Companion.getSafeString
import com.kl3jvi.animity.utils.Constants.Companion.showSnack
import com.kl3jvi.animity.utils.Resource
Expand All @@ -49,6 +47,7 @@ import okhttp3.OkHttpClient
import okhttp3.dnsoverhttps.DnsOverHttps
import java.io.File
import java.net.InetAddress
import kotlin.math.pow


@ExperimentalCoroutinesApi
Expand Down Expand Up @@ -298,7 +297,7 @@ class PlayerActivity : AppCompatActivity() {
// }

private fun buildMediaSource(mediaItem: MediaItem, url: String): MediaSource {
if (url.contains("m3u8")) {
return if (url.contains("m3u8")) {
val appCache = Cache(File("cacheDir", "okhttpcache"), 10 * 1024 * 1024)
val bootstrapClient = OkHttpClient.Builder().cache(appCache).build()

Expand All @@ -308,24 +307,24 @@ class PlayerActivity : AppCompatActivity() {
.build()

val client = bootstrapClient.newBuilder().dns(dns).build()

val dataSource = {
val dataSource = OkHttpDataSource.Factory(client)
.setUserAgent(USER_AGENT)
.setUserAgent(Constants.USER_AGENT)
.setDefaultRequestProperties(hashMapOf("Referer" to REFERER))
dataSource.createDataSource()
dataSource.createDataSource();

}
return HlsMediaSource.Factory(dataSource)
HlsMediaSource.Factory(dataSource)
.setAllowChunklessPreparation(true)
.createMediaSource(mediaItem)
} else {
val dataSource = {
val dataSource: DataSource.Factory = DefaultHttpDataSource.Factory()
.setUserAgent(USER_AGENT)
.setUserAgent(Constants.USER_AGENT)
.setDefaultRequestProperties(hashMapOf("Referer" to REFERER))
dataSource.createDataSource()
}
return ProgressiveMediaSource.Factory(dataSource)
ProgressiveMediaSource.Factory(dataSource)
.createMediaSource(mediaItem)
}
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/layout/exo_player_custom_controls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
android:layout_marginStart="@dimen/dp_10"
android:layout_marginEnd="@dimen/dp_10"
android:fontFamily="sans-serif"
android:gravity="start"

android:gravity="center"
android:maxWidth="450dp"
android:maxLines="2"
android:textColor="@android:color/white"
Expand All @@ -48,7 +49,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_10"
android:layout_marginEnd="@dimen/dp_10"
android:gravity="start"
android:gravity="center"
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="@+id/exo_track_selection_view"
app:layout_constraintEnd_toStartOf="@+id/exo_track_selection_view"
Expand Down Expand Up @@ -239,7 +240,7 @@
android:layout_marginBottom="16dp"
android:layout_weight="1"
android:contentDescription="@string/exo_controls_rewind_description"
app:bar_height="2dp"
app:bar_height="3dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/exo_duration"
app:layout_constraintStart_toEndOf="@id/exo_position"
Expand Down

0 comments on commit c2a3da3

Please sign in to comment.