Skip to content

Commit

Permalink
Merge pull request #54 from bagashyt/audio_focus
Browse files Browse the repository at this point in the history
Added Audio focus handle on Exoplayer
  • Loading branch information
justdvnsh authored Oct 7, 2021
2 parents 1d954f1 + d99fba3 commit 3846d0b
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import com.google.android.exoplayer2.*
import com.google.android.exoplayer2.Player.*
import com.google.android.exoplayer2.audio.AudioAttributes
import com.google.android.exoplayer2.source.ExtractorMediaSource
import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.source.hls.HlsDataSourceFactory
Expand Down Expand Up @@ -176,6 +177,7 @@ class PlayerFragment: Fragment(), PlayerControlListener {
private fun play(data: PlayerScreenModel) {
exoPlayer.prepare(buildMediaSource(data.streamingUrl.toUri()))
exoPlayer.playWhenReady = true
audioFocus()
}

private fun buildMediaSource(uri: Uri): MediaSource {
Expand Down Expand Up @@ -294,6 +296,14 @@ class PlayerFragment: Fragment(), PlayerControlListener {
}
}

private fun audioFocus(){
val audioAttributes: AudioAttributes = AudioAttributes.Builder()
.setUsage(C.USAGE_MEDIA)
.setContentType(C.CONTENT_TYPE_MOVIE)
.build()
exoPlayer.setAudioAttributes(audioAttributes, true)
}

private fun speedControl(){
var playbackPosition = 2
val alertDialog: AlertDialog.Builder = AlertDialog.Builder(requireContext())
Expand Down

0 comments on commit 3846d0b

Please sign in to comment.