mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
updated deprecated exoplayer functions
This commit is contained in:
parent
5c0bab96a4
commit
1e858ddd04
1 changed files with 164 additions and 73 deletions
|
@ -46,7 +46,7 @@ import com.fasterxml.jackson.module.kotlin.KotlinModule
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import com.google.android.exoplayer2.*
|
import com.google.android.exoplayer2.*
|
||||||
import com.google.android.exoplayer2.C.TIME_UNSET
|
import com.google.android.exoplayer2.C.TIME_UNSET
|
||||||
import com.google.android.exoplayer2.database.ExoDatabaseProvider
|
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider
|
||||||
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory
|
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory
|
||||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
|
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
|
||||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
|
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
|
||||||
|
@ -255,7 +255,7 @@ class PlayerFragment : Fragment() {
|
||||||
private lateinit var uriData: UriData
|
private lateinit var uriData: UriData
|
||||||
private var isDownloadedFile = false
|
private var isDownloadedFile = false
|
||||||
private var isShowing = true
|
private var isShowing = true
|
||||||
private lateinit var exoPlayer: SimpleExoPlayer
|
private lateinit var exoPlayer: ExoPlayer
|
||||||
|
|
||||||
//private var currentPercentage = 0
|
//private var currentPercentage = 0
|
||||||
// private var hasNextEpisode = true
|
// private var hasNextEpisode = true
|
||||||
|
@ -429,7 +429,9 @@ class PlayerFragment : Fragment() {
|
||||||
val rmin = min % 60
|
val rmin = min % 60
|
||||||
val h = ceil((min - rmin) / 60.0).toInt()
|
val h = ceil((min - rmin) / 60.0).toInt()
|
||||||
//int rh = h;// h % 24;
|
//int rh = h;// h % 24;
|
||||||
return (if (h > 0) forceLetters(h) + ":" else "") + (if (rmin >= 0 || h >= 0) forceLetters(rmin) + ":" else "") + forceLetters(
|
return (if (h > 0) forceLetters(h) + ":" else "") + (if (rmin >= 0 || h >= 0) forceLetters(
|
||||||
|
rmin
|
||||||
|
) + ":" else "") + forceLetters(
|
||||||
rsec
|
rsec
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -439,9 +441,12 @@ class PlayerFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private var swipeEnabled = true //<settingsManager!!.getBoolean("swipe_enabled", true)
|
private var swipeEnabled = true //<settingsManager!!.getBoolean("swipe_enabled", true)
|
||||||
private var swipeVerticalEnabled = true//settingsManager.getBoolean("swipe_vertical_enabled", true)
|
private var swipeVerticalEnabled =
|
||||||
private var playBackSpeedEnabled = true//settingsManager!!.getBoolean("playback_speed_enabled", false)
|
true//settingsManager.getBoolean("swipe_vertical_enabled", true)
|
||||||
private var playerResizeEnabled = true//settingsManager!!.getBoolean("player_resize_enabled", false)
|
private var playBackSpeedEnabled =
|
||||||
|
true//settingsManager!!.getBoolean("playback_speed_enabled", false)
|
||||||
|
private var playerResizeEnabled =
|
||||||
|
true//settingsManager!!.getBoolean("player_resize_enabled", false)
|
||||||
private var doubleTapEnabled = false
|
private var doubleTapEnabled = false
|
||||||
private var useSystemBrightness = false
|
private var useSystemBrightness = false
|
||||||
private var useTrueSystemBrightness = false
|
private var useTrueSystemBrightness = false
|
||||||
|
@ -555,8 +560,10 @@ class PlayerFragment : Fragment() {
|
||||||
if (hasPassedVerticalSwipeThreshold) {
|
if (hasPassedVerticalSwipeThreshold) {
|
||||||
if (currentX > width * 0.5) {
|
if (currentX > width * 0.5) {
|
||||||
if (audioManager != null && progressBarLeftHolder != null) {
|
if (audioManager != null && progressBarLeftHolder != null) {
|
||||||
val currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
|
val currentVolume =
|
||||||
val maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
|
audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
|
||||||
|
val maxVolume =
|
||||||
|
audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
|
||||||
|
|
||||||
if (progressBarLeftHolder?.alpha ?: 0f <= 0f) {
|
if (progressBarLeftHolder?.alpha ?: 0f <= 0f) {
|
||||||
cachedVolume = currentVolume.toFloat() / maxVolume.toFloat()
|
cachedVolume = currentVolume.toFloat() / maxVolume.toFloat()
|
||||||
|
@ -583,7 +590,11 @@ class PlayerFragment : Fragment() {
|
||||||
val newVolumeAdjusted =
|
val newVolumeAdjusted =
|
||||||
if (desiredVol < currentVolume) AudioManager.ADJUST_LOWER else AudioManager.ADJUST_RAISE
|
if (desiredVol < currentVolume) AudioManager.ADJUST_LOWER else AudioManager.ADJUST_RAISE
|
||||||
|
|
||||||
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, newVolumeAdjusted, 0)
|
audioManager.adjustStreamVolume(
|
||||||
|
AudioManager.STREAM_MUSIC,
|
||||||
|
newVolumeAdjusted,
|
||||||
|
0
|
||||||
|
)
|
||||||
}
|
}
|
||||||
//audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, newVolume, 0)
|
//audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, newVolume, 0)
|
||||||
}
|
}
|
||||||
|
@ -609,7 +620,8 @@ class PlayerFragment : Fragment() {
|
||||||
}
|
}
|
||||||
prevDiffX = diffX
|
prevDiffX = diffX
|
||||||
|
|
||||||
skipTime = ((exoPlayer.duration * (diffX * diffX) / 10) * (if (diffX < 0) -1 else 1)).toLong()
|
skipTime =
|
||||||
|
((exoPlayer.duration * (diffX * diffX) / 10) * (if (diffX < 0) -1 else 1)).toLong()
|
||||||
if (isMovingStartTime + skipTime < 0) {
|
if (isMovingStartTime + skipTime < 0) {
|
||||||
skipTime = -isMovingStartTime
|
skipTime = -isMovingStartTime
|
||||||
} else if (isMovingStartTime + skipTime > exoPlayer.duration) {
|
} else if (isMovingStartTime + skipTime > exoPlayer.duration) {
|
||||||
|
@ -618,7 +630,12 @@ class PlayerFragment : Fragment() {
|
||||||
if ((abs(skipTime) > 3000 || hasPassedSkipLimit) && !preventHorizontalSwipe) {
|
if ((abs(skipTime) > 3000 || hasPassedSkipLimit) && !preventHorizontalSwipe) {
|
||||||
hasPassedSkipLimit = true
|
hasPassedSkipLimit = true
|
||||||
val timeString =
|
val timeString =
|
||||||
"${convertTimeToString((isMovingStartTime + skipTime) / 1000.0)} [${(if (abs(skipTime) < 1000) "" else (if (skipTime > 0) "+" else "-"))}${
|
"${convertTimeToString((isMovingStartTime + skipTime) / 1000.0)} [${
|
||||||
|
(if (abs(
|
||||||
|
skipTime
|
||||||
|
) < 1000
|
||||||
|
) "" else (if (skipTime > 0) "+" else "-"))
|
||||||
|
}${
|
||||||
convertTimeToString(abs(skipTime / 1000.0))
|
convertTimeToString(abs(skipTime / 1000.0))
|
||||||
}]"
|
}]"
|
||||||
timeText.alpha = 1f
|
timeText.alpha = 1f
|
||||||
|
@ -669,7 +686,8 @@ class PlayerFragment : Fragment() {
|
||||||
val data = localData
|
val data = localData
|
||||||
|
|
||||||
if (this::exoPlayer.isInitialized && exoPlayer.currentPosition >= 0) {
|
if (this::exoPlayer.isInitialized && exoPlayer.currentPosition >= 0) {
|
||||||
val percentage = ((position ?: exoPlayer.currentPosition) * 100 / exoPlayer.contentDuration).toInt()
|
val percentage =
|
||||||
|
((position ?: exoPlayer.currentPosition) * 100 / exoPlayer.contentDuration).toInt()
|
||||||
val hasNext = hasNextEpisode()
|
val hasNext = hasNextEpisode()
|
||||||
|
|
||||||
if (percentage >= AUTOLOAD_NEXT_EPISODE_PERCENTAGE && hasNext) {
|
if (percentage >= AUTOLOAD_NEXT_EPISODE_PERCENTAGE && hasNext) {
|
||||||
|
@ -745,7 +763,8 @@ class PlayerFragment : Fragment() {
|
||||||
safeReleasePlayer()
|
safeReleasePlayer()
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SettingsContentObserver(handler: Handler?, val activity: Activity) : ContentObserver(handler) {
|
private class SettingsContentObserver(handler: Handler?, val activity: Activity) :
|
||||||
|
ContentObserver(handler) {
|
||||||
private val audioManager = activity.getSystemService(AUDIO_SERVICE) as? AudioManager
|
private val audioManager = activity.getSystemService(AUDIO_SERVICE) as? AudioManager
|
||||||
override fun onChange(selfChange: Boolean) {
|
override fun onChange(selfChange: Boolean) {
|
||||||
val currentVolume = audioManager?.getStreamVolume(AudioManager.STREAM_MUSIC)
|
val currentVolume = audioManager?.getStreamVolume(AudioManager.STREAM_MUSIC)
|
||||||
|
@ -809,7 +828,13 @@ class PlayerFragment : Fragment() {
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (isDownloadedFile) {
|
if (isDownloadedFile) {
|
||||||
ctx.setLastWatched(uriData.parentId, uriData.id, uriData.episode, uriData.season, true)
|
ctx.setLastWatched(
|
||||||
|
uriData.parentId,
|
||||||
|
uriData.id,
|
||||||
|
uriData.episode,
|
||||||
|
uriData.season,
|
||||||
|
true
|
||||||
|
)
|
||||||
} else
|
} else
|
||||||
viewModel.reloadEpisodes(ctx)
|
viewModel.reloadEpisodes(ctx)
|
||||||
}
|
}
|
||||||
|
@ -972,11 +997,25 @@ class PlayerFragment : Fragment() {
|
||||||
if (exoPlayer.isPlaying) {
|
if (exoPlayer.isPlaying) {
|
||||||
actions.add(getRemoteAction(R.drawable.netflix_pause, "Pause", PlayerEventType.Pause))
|
actions.add(getRemoteAction(R.drawable.netflix_pause, "Pause", PlayerEventType.Pause))
|
||||||
} else {
|
} else {
|
||||||
actions.add(getRemoteAction(R.drawable.ic_baseline_play_arrow_24, "Play", PlayerEventType.Play))
|
actions.add(
|
||||||
|
getRemoteAction(
|
||||||
|
R.drawable.ic_baseline_play_arrow_24,
|
||||||
|
"Play",
|
||||||
|
PlayerEventType.Play
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.add(getRemoteAction(R.drawable.go_forward_30, "Go Forward", PlayerEventType.SeekForward))
|
actions.add(
|
||||||
activity?.setPictureInPictureParams(PictureInPictureParams.Builder().setActions(actions).build())
|
getRemoteAction(
|
||||||
|
R.drawable.go_forward_30,
|
||||||
|
"Go Forward",
|
||||||
|
PlayerEventType.SeekForward
|
||||||
|
)
|
||||||
|
)
|
||||||
|
activity?.setPictureInPictureParams(
|
||||||
|
PictureInPictureParams.Builder().setActions(actions).build()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var receiver: BroadcastReceiver? = null
|
private var receiver: BroadcastReceiver? = null
|
||||||
|
@ -1117,12 +1156,29 @@ class PlayerFragment : Fragment() {
|
||||||
}
|
}
|
||||||
PlayerEventType.ShowSpeed.value -> {
|
PlayerEventType.ShowSpeed.value -> {
|
||||||
val speedsText =
|
val speedsText =
|
||||||
listOf("0.5x", "0.75x", "0.85x", "1x", "1.15x", "1.25x", "1.4x", "1.5x", "1.75x", "2x")
|
listOf(
|
||||||
val speedsNumbers = listOf(0.5f, 0.75f, 0.85f, 1f, 1.15f, 1.25f, 1.4f, 1.5f, 1.75f, 2f)
|
"0.5x",
|
||||||
|
"0.75x",
|
||||||
|
"0.85x",
|
||||||
|
"1x",
|
||||||
|
"1.15x",
|
||||||
|
"1.25x",
|
||||||
|
"1.4x",
|
||||||
|
"1.5x",
|
||||||
|
"1.75x",
|
||||||
|
"2x"
|
||||||
|
)
|
||||||
|
val speedsNumbers =
|
||||||
|
listOf(0.5f, 0.75f, 0.85f, 1f, 1.15f, 1.25f, 1.4f, 1.5f, 1.75f, 2f)
|
||||||
val speedIndex = speedsNumbers.indexOf(playbackSpeed)
|
val speedIndex = speedsNumbers.indexOf(playbackSpeed)
|
||||||
|
|
||||||
context?.let { ctx ->
|
context?.let { ctx ->
|
||||||
ctx.showDialog(speedsText, speedIndex, ctx.getString(R.string.player_speed), false, {
|
ctx.showDialog(
|
||||||
|
speedsText,
|
||||||
|
speedIndex,
|
||||||
|
ctx.getString(R.string.player_speed),
|
||||||
|
false,
|
||||||
|
{
|
||||||
activity?.hideSystemUI()
|
activity?.hideSystemUI()
|
||||||
}) { index ->
|
}) { index ->
|
||||||
playbackSpeed = speedsNumbers[index]
|
playbackSpeed = speedsNumbers[index]
|
||||||
|
@ -1130,7 +1186,8 @@ class PlayerFragment : Fragment() {
|
||||||
val param = PlaybackParameters(playbackSpeed)
|
val param = PlaybackParameters(playbackSpeed)
|
||||||
exoPlayer.playbackParameters = param
|
exoPlayer.playbackParameters = param
|
||||||
playback_speed_btt?.text =
|
playback_speed_btt?.text =
|
||||||
getString(R.string.player_speed_text_format).format(playbackSpeed).replace(".0x", "x")
|
getString(R.string.player_speed_text_format).format(playbackSpeed)
|
||||||
|
.replace(".0x", "x")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1139,7 +1196,8 @@ class PlayerFragment : Fragment() {
|
||||||
context?.let { ctx ->
|
context?.let { ctx ->
|
||||||
//val isPlaying = exoPlayer.isPlaying
|
//val isPlaying = exoPlayer.isPlaying
|
||||||
exoPlayer.pause()
|
exoPlayer.pause()
|
||||||
val currentSubtitles = context?.getSubs()?.map { it.lang } ?: activeSubtitles
|
val currentSubtitles =
|
||||||
|
context?.getSubs()?.map { it.lang } ?: activeSubtitles
|
||||||
|
|
||||||
val sourceBuilder = AlertDialog.Builder(ctx, R.style.AlertDialogCustomBlack)
|
val sourceBuilder = AlertDialog.Builder(ctx, R.style.AlertDialogCustomBlack)
|
||||||
.setView(R.layout.player_select_source_and_subs)
|
.setView(R.layout.player_select_source_and_subs)
|
||||||
|
@ -1147,10 +1205,14 @@ class PlayerFragment : Fragment() {
|
||||||
val sourceDialog = sourceBuilder.create()
|
val sourceDialog = sourceBuilder.create()
|
||||||
sourceDialog.show()
|
sourceDialog.show()
|
||||||
// bottomSheetDialog.setContentView(R.layout.sort_bottom_sheet)
|
// bottomSheetDialog.setContentView(R.layout.sort_bottom_sheet)
|
||||||
val providerList = sourceDialog.findViewById<ListView>(R.id.sort_providers)!!
|
val providerList =
|
||||||
val subtitleList = sourceDialog.findViewById<ListView>(R.id.sort_subtitles)!!
|
sourceDialog.findViewById<ListView>(R.id.sort_providers)!!
|
||||||
val applyButton = sourceDialog.findViewById<MaterialButton>(R.id.apply_btt)!!
|
val subtitleList =
|
||||||
val cancelButton = sourceDialog.findViewById<MaterialButton>(R.id.cancel_btt)!!
|
sourceDialog.findViewById<ListView>(R.id.sort_subtitles)!!
|
||||||
|
val applyButton =
|
||||||
|
sourceDialog.findViewById<MaterialButton>(R.id.apply_btt)!!
|
||||||
|
val cancelButton =
|
||||||
|
sourceDialog.findViewById<MaterialButton>(R.id.cancel_btt)!!
|
||||||
val subsSettings = sourceDialog.findViewById<View>(R.id.subs_settings)!!
|
val subsSettings = sourceDialog.findViewById<View>(R.id.subs_settings)!!
|
||||||
|
|
||||||
subsSettings.setOnClickListener {
|
subsSettings.setOnClickListener {
|
||||||
|
@ -1164,7 +1226,8 @@ class PlayerFragment : Fragment() {
|
||||||
|
|
||||||
val nonSortedUrls = getUrls()
|
val nonSortedUrls = getUrls()
|
||||||
if (nonSortedUrls.isNullOrEmpty()) {
|
if (nonSortedUrls.isNullOrEmpty()) {
|
||||||
sourceDialog.findViewById<LinearLayout>(R.id.sort_sources_holder)?.visibility = GONE
|
sourceDialog.findViewById<LinearLayout>(R.id.sort_sources_holder)?.visibility =
|
||||||
|
GONE
|
||||||
} else {
|
} else {
|
||||||
sources = sortUrls(nonSortedUrls)
|
sources = sortUrls(nonSortedUrls)
|
||||||
startSource = sources.indexOf(getCurrentUrl())
|
startSource = sources.indexOf(getCurrentUrl())
|
||||||
|
@ -1195,7 +1258,8 @@ class PlayerFragment : Fragment() {
|
||||||
var subtitleIndex = startIndexFromMap
|
var subtitleIndex = startIndexFromMap
|
||||||
|
|
||||||
if (currentSubtitles.isEmpty()) {
|
if (currentSubtitles.isEmpty()) {
|
||||||
sourceDialog.findViewById<LinearLayout>(R.id.sort_subtitles_holder)?.visibility = GONE
|
sourceDialog.findViewById<LinearLayout>(R.id.sort_subtitles_holder)?.visibility =
|
||||||
|
GONE
|
||||||
} else {
|
} else {
|
||||||
val subsArrayAdapter =
|
val subsArrayAdapter =
|
||||||
ArrayAdapter<String>(ctx, R.layout.sort_bottom_single_choice)
|
ArrayAdapter<String>(ctx, R.layout.sort_bottom_single_choice)
|
||||||
|
@ -1219,7 +1283,8 @@ class PlayerFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
applyButton.setOnClickListener {
|
applyButton.setOnClickListener {
|
||||||
if (this::exoPlayer.isInitialized) playbackPosition = exoPlayer.currentPosition
|
if (this::exoPlayer.isInitialized) playbackPosition =
|
||||||
|
exoPlayer.currentPosition
|
||||||
|
|
||||||
var init = false
|
var init = false
|
||||||
if (sourceIndex != startSource) {
|
if (sourceIndex != startSource) {
|
||||||
|
@ -1270,7 +1335,8 @@ class PlayerFragment : Fragment() {
|
||||||
//val textRendererIndex = getRendererIndex(C.TRACK_TYPE_TEXT) ?: return@setOnClickListener
|
//val textRendererIndex = getRendererIndex(C.TRACK_TYPE_TEXT) ?: return@setOnClickListener
|
||||||
val realLang = if (lang.isNullOrBlank()) "" else lang.trimEnd()
|
val realLang = if (lang.isNullOrBlank()) "" else lang.trimEnd()
|
||||||
preferredSubtitles =
|
preferredSubtitles =
|
||||||
if (realLang.length == 2) SubtitleHelper.fromTwoLettersToLanguage(realLang) ?: realLang else realLang
|
if (realLang.length == 2) SubtitleHelper.fromTwoLettersToLanguage(realLang)
|
||||||
|
?: realLang else realLang
|
||||||
|
|
||||||
if (!this::exoPlayer.isInitialized) return
|
if (!this::exoPlayer.isInitialized) return
|
||||||
(exoPlayer.trackSelector as DefaultTrackSelector?)?.let { trackSelector ->
|
(exoPlayer.trackSelector as DefaultTrackSelector?)?.let { trackSelector ->
|
||||||
|
@ -1310,12 +1376,20 @@ class PlayerFragment : Fragment() {
|
||||||
|
|
||||||
settingsManager = PreferenceManager.getDefaultSharedPreferences(activity)
|
settingsManager = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
context?.let { ctx ->
|
context?.let { ctx ->
|
||||||
swipeEnabled = settingsManager.getBoolean(ctx.getString(R.string.swipe_enabled_key), true)
|
swipeEnabled =
|
||||||
swipeVerticalEnabled = settingsManager.getBoolean(ctx.getString(R.string.swipe_vertical_enabled_key), true)
|
settingsManager.getBoolean(ctx.getString(R.string.swipe_enabled_key), true)
|
||||||
playBackSpeedEnabled = settingsManager.getBoolean(ctx.getString(R.string.playback_speed_enabled_key), false)
|
swipeVerticalEnabled =
|
||||||
playerResizeEnabled = settingsManager.getBoolean(ctx.getString(R.string.player_resize_enabled_key), true)
|
settingsManager.getBoolean(ctx.getString(R.string.swipe_vertical_enabled_key), true)
|
||||||
doubleTapEnabled = settingsManager.getBoolean(ctx.getString(R.string.double_tap_enabled_key), false)
|
playBackSpeedEnabled = settingsManager.getBoolean(
|
||||||
useSystemBrightness = settingsManager.getBoolean(ctx.getString(R.string.use_system_brightness_key), false)
|
ctx.getString(R.string.playback_speed_enabled_key),
|
||||||
|
false
|
||||||
|
)
|
||||||
|
playerResizeEnabled =
|
||||||
|
settingsManager.getBoolean(ctx.getString(R.string.player_resize_enabled_key), true)
|
||||||
|
doubleTapEnabled =
|
||||||
|
settingsManager.getBoolean(ctx.getString(R.string.double_tap_enabled_key), false)
|
||||||
|
useSystemBrightness =
|
||||||
|
settingsManager.getBoolean(ctx.getString(R.string.use_system_brightness_key), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (swipeVerticalEnabled)
|
if (swipeVerticalEnabled)
|
||||||
|
@ -1342,7 +1416,8 @@ class PlayerFragment : Fragment() {
|
||||||
VISIBLE
|
VISIBLE
|
||||||
castContext.addCastStateListener { state ->
|
castContext.addCastStateListener { state ->
|
||||||
if (player_media_route_button != null) {
|
if (player_media_route_button != null) {
|
||||||
player_media_route_button?.isVisible = state != CastState.NO_DEVICES_AVAILABLE
|
player_media_route_button?.isVisible =
|
||||||
|
state != CastState.NO_DEVICES_AVAILABLE
|
||||||
|
|
||||||
if (state == CastState.CONNECTED) {
|
if (state == CastState.CONNECTED) {
|
||||||
if (!this::exoPlayer.isInitialized) return@addCastStateListener
|
if (!this::exoPlayer.isInitialized) return@addCastStateListener
|
||||||
|
@ -1358,7 +1433,8 @@ class PlayerFragment : Fragment() {
|
||||||
epData.index,
|
epData.index,
|
||||||
episodes,
|
episodes,
|
||||||
links,
|
links,
|
||||||
context?.getSubs(supportsDownloadedFiles = false) ?: emptyList(),
|
context?.getSubs(supportsDownloadedFiles = false)
|
||||||
|
?: emptyList(),
|
||||||
index,
|
index,
|
||||||
exoPlayer.currentPosition
|
exoPlayer.currentPosition
|
||||||
)
|
)
|
||||||
|
@ -1534,7 +1610,8 @@ class PlayerFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val fastForwardTime = settingsManager.getInt(getString(R.string.fast_forward_button_time_key), 10)
|
val fastForwardTime =
|
||||||
|
settingsManager.getInt(getString(R.string.fast_forward_button_time_key), 10)
|
||||||
exo_rew_text?.text = getString(R.string.rew_text_regular_format).format(fastForwardTime)
|
exo_rew_text?.text = getString(R.string.rew_text_regular_format).format(fastForwardTime)
|
||||||
exo_ffwd_text?.text = getString(R.string.ffw_text_regular_format).format(fastForwardTime)
|
exo_ffwd_text?.text = getString(R.string.ffw_text_regular_format).format(fastForwardTime)
|
||||||
fun rewind() {
|
fun rewind() {
|
||||||
|
@ -1551,7 +1628,8 @@ class PlayerFragment : Fragment() {
|
||||||
|
|
||||||
override fun onAnimationEnd(animation: Animation?) {
|
override fun onAnimationEnd(animation: Animation?) {
|
||||||
exo_rew_text?.post {
|
exo_rew_text?.post {
|
||||||
exo_rew_text?.text = getString(R.string.rew_text_regular_format).format(fastForwardTime)
|
exo_rew_text?.text =
|
||||||
|
getString(R.string.rew_text_regular_format).format(fastForwardTime)
|
||||||
player_rew_holder?.alpha = if (isShowing) 1f else 0f
|
player_rew_holder?.alpha = if (isShowing) 1f else 0f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1578,7 +1656,8 @@ class PlayerFragment : Fragment() {
|
||||||
|
|
||||||
override fun onAnimationEnd(animation: Animation?) {
|
override fun onAnimationEnd(animation: Animation?) {
|
||||||
exo_ffwd_text?.post {
|
exo_ffwd_text?.post {
|
||||||
exo_ffwd_text?.text = getString(R.string.ffw_text_regular_format).format(fastForwardTime)
|
exo_ffwd_text?.text =
|
||||||
|
getString(R.string.ffw_text_regular_format).format(fastForwardTime)
|
||||||
player_ffwd_holder?.alpha = if (isShowing) 1f else 0f
|
player_ffwd_holder?.alpha = if (isShowing) 1f else 0f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1704,7 +1783,8 @@ class PlayerFragment : Fragment() {
|
||||||
if (isDownloadedFile) {
|
if (isDownloadedFile) {
|
||||||
if (!supportsDownloadedFiles) return null
|
if (!supportsDownloadedFiles) return null
|
||||||
val list = ArrayList<SubtitleFile>()
|
val list = ArrayList<SubtitleFile>()
|
||||||
VideoDownloadManager.getFolder(this, uriData.relativePath, uriData.basePath)?.forEach { file ->
|
VideoDownloadManager.getFolder(this, uriData.relativePath, uriData.basePath)
|
||||||
|
?.forEach { file ->
|
||||||
val name = uriData.displayName.removeSuffix(".mp4")
|
val name = uriData.displayName.removeSuffix(".mp4")
|
||||||
if (file.first != uriData.displayName && file.first.startsWith(name)) {
|
if (file.first != uriData.displayName && file.first.startsWith(name)) {
|
||||||
val realName = file.first.removePrefix(name)
|
val realName = file.first.removePrefix(name)
|
||||||
|
@ -1965,7 +2045,9 @@ class PlayerFragment : Fragment() {
|
||||||
exoPlayer.release()
|
exoPlayer.release()
|
||||||
}
|
}
|
||||||
val isOnline =
|
val isOnline =
|
||||||
currentUrl != null && (currentUrl.url.startsWith("https://") || currentUrl.url.startsWith("http://"))
|
currentUrl != null && (currentUrl.url.startsWith("https://") || currentUrl.url.startsWith(
|
||||||
|
"http://"
|
||||||
|
))
|
||||||
|
|
||||||
if (settingsManager.getBoolean("ignore_ssl", true) && !isDownloadedFile) {
|
if (settingsManager.getBoolean("ignore_ssl", true) && !isDownloadedFile) {
|
||||||
// Disables ssl check
|
// Disables ssl check
|
||||||
|
@ -1998,24 +2080,25 @@ class PlayerFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val subs = context?.getSubs() ?: emptyList()
|
val subs = context?.getSubs() ?: emptyList()
|
||||||
val subItems = ArrayList<MediaItem.Subtitle>()
|
val subItems = ArrayList<MediaItem.SubtitleConfiguration>()
|
||||||
val subItemsId = ArrayList<String>()
|
val subItemsId = ArrayList<String>()
|
||||||
|
|
||||||
for (sub in sortSubs(subs)) {
|
for (sub in sortSubs(subs)) {
|
||||||
val langId = sub.lang.trimEnd() //SubtitleHelper.fromLanguageToTwoLetters(it.lang) ?: it.lang
|
val langId =
|
||||||
|
sub.lang.trimEnd() //SubtitleHelper.fromLanguageToTwoLetters(it.lang) ?: it.lang
|
||||||
subItemsId.add(langId)
|
subItemsId.add(langId)
|
||||||
subItems.add(
|
subItems.add(
|
||||||
MediaItem.Subtitle(
|
MediaItem.SubtitleConfiguration.Builder(Uri.parse(sub.url))
|
||||||
Uri.parse(sub.url),
|
.setMimeType(sub.url.toSubtitleMimeType())
|
||||||
sub.url.toSubtitleMimeType(),
|
.setLanguage("_$langId")
|
||||||
"_$langId",
|
.setSelectionFlags(C.SELECTION_FLAG_DEFAULT)
|
||||||
C.SELECTION_FLAG_DEFAULT
|
.build()
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
activeSubtitles = subItemsId
|
activeSubtitles = subItemsId
|
||||||
mediaItemBuilder.setSubtitles(subItems)
|
mediaItemBuilder.setSubtitleConfigurations(subItems)
|
||||||
|
|
||||||
//might add https://github.com/ed828a/Aihua/blob/1896f46888b5a954b367e83f40b845ce174a2328/app/src/main/java/com/dew/aihua/player/playerUI/VideoPlayer.kt#L287 toggle caps
|
//might add https://github.com/ed828a/Aihua/blob/1896f46888b5a954b367e83f40b845ce174a2328/app/src/main/java/com/dew/aihua/player/playerUI/VideoPlayer.kt#L287 toggle caps
|
||||||
|
|
||||||
|
@ -2055,11 +2138,11 @@ class PlayerFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
normalSafeApiCall {
|
normalSafeApiCall {
|
||||||
val databaseProvider = ExoDatabaseProvider(requireContext())
|
val databaseProvider = StandaloneDatabaseProvider(requireContext())
|
||||||
simpleCache = SimpleCache(
|
simpleCache = simpleCache ?: SimpleCache(
|
||||||
File(
|
File(
|
||||||
requireContext().filesDir, "exoplayer"
|
requireContext().filesDir, "exoplayer"
|
||||||
),
|
).also { it.deleteOnExit() }, // Ensures always fresh file
|
||||||
LeastRecentlyUsedCacheEvictor(cacheSize),
|
LeastRecentlyUsedCacheEvictor(cacheSize),
|
||||||
databaseProvider
|
databaseProvider
|
||||||
)
|
)
|
||||||
|
@ -2071,7 +2154,7 @@ class PlayerFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val _exoPlayer =
|
val _exoPlayer =
|
||||||
SimpleExoPlayer.Builder(requireContext())
|
ExoPlayer.Builder(requireContext())
|
||||||
.setTrackSelector(trackSelector)
|
.setTrackSelector(trackSelector)
|
||||||
|
|
||||||
exoPlayer = _exoPlayer.build().apply {
|
exoPlayer = _exoPlayer.build().apply {
|
||||||
|
@ -2105,7 +2188,8 @@ class PlayerFragment : Fragment() {
|
||||||
// Sets the speed
|
// Sets the speed
|
||||||
exoPlayer.playbackParameters = PlaybackParameters(playbackSpeed)
|
exoPlayer.playbackParameters = PlaybackParameters(playbackSpeed)
|
||||||
playback_speed_btt?.text =
|
playback_speed_btt?.text =
|
||||||
getString(R.string.player_speed_text_format).format(playbackSpeed).replace(".0x", "x")
|
getString(R.string.player_speed_text_format).format(playbackSpeed)
|
||||||
|
.replace(".0x", "x")
|
||||||
|
|
||||||
var hName: String? = null
|
var hName: String? = null
|
||||||
var epEpisode: Int? = null
|
var epEpisode: Int? = null
|
||||||
|
@ -2311,7 +2395,10 @@ class PlayerFragment : Fragment() {
|
||||||
var currentQuality = Qualities.values().last().value
|
var currentQuality = Qualities.values().last().value
|
||||||
context?.let { ctx ->
|
context?.let { ctx ->
|
||||||
if (this::settingsManager.isInitialized)
|
if (this::settingsManager.isInitialized)
|
||||||
currentQuality = settingsManager.getInt(ctx.getString(R.string.watch_quality_pref), currentQuality)
|
currentQuality = settingsManager.getInt(
|
||||||
|
ctx.getString(R.string.watch_quality_pref),
|
||||||
|
currentQuality
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentId = sortedUrls.first().getId() // lowest quality
|
var currentId = sortedUrls.first().getId() // lowest quality
|
||||||
|
@ -2358,7 +2445,11 @@ class PlayerFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
return inflater.inflate(R.layout.fragment_player, container, false)
|
return inflater.inflate(R.layout.fragment_player, container, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue