Skip to content

Commit

Permalink
fix #127
Browse files Browse the repository at this point in the history
  • Loading branch information
itszechs committed Dec 25, 2024
1 parent 5064f27 commit 48c4822
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions app/src/main/java/zechs/drive/stream/ui/player2/MPVActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.media.AudioManager
import android.media.AudioManager.*
import android.media.AudioManager.AUDIOFOCUS_GAIN
import android.media.AudioManager.AUDIOFOCUS_LOSS
import android.media.AudioManager.AUDIOFOCUS_LOSS_TRANSIENT
import android.media.AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK
import android.media.AudioManager.AUDIOFOCUS_REQUEST_GRANTED
import android.media.AudioManager.OnAudioFocusChangeListener
import android.media.AudioManager.STREAM_MUSIC
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -198,13 +204,15 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver {
if (!wasPlayerPaused) player.paused = false
}
}

AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {
MPVLib.command(arrayOf("multiply", "volume", AUDIO_FOCUS_DUCKING.toString()))
audioFocusRestore = {
val inv = 1f / AUDIO_FOCUS_DUCKING
MPVLib.command(arrayOf("multiply", "volume", inv.toString()))
}
}

AUDIOFOCUS_GAIN -> {
audioFocusRestore()
audioFocusRestore = {}
Expand Down Expand Up @@ -310,17 +318,25 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver {

private fun skipForward() {
val currentPos = player.timePos ?: return
val newPos = currentPos + SKIP_DURATION
val totalDuration = player.duration ?: return
var newPos = currentPos + SKIP_DURATION
if (newPos > totalDuration) {
newPos = totalDuration
}
if (newPos == currentPos) return
player.timePos = newPos
}

private fun rewindBackward() {
val currentPos = player.timePos ?: return
val newPos = currentPos - SKIP_DURATION
var newPos = currentPos - SKIP_DURATION
if (newPos < 0) {
newPos = 0
}
if (newPos == currentPos) return
player.timePos = newPos
}


data class TrackData(
val track_id: Int,
val track_type: String
Expand Down Expand Up @@ -463,6 +479,7 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver {
)
}
}

else -> {
controller.btnRotate.apply {
orientation = Orientation.LANDSCAPE
Expand Down

0 comments on commit 48c4822

Please sign in to comment.