Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Audio focus handle on Exoplayer #54

Merged
merged 2 commits into from
Oct 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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