Created
January 27, 2019 19:45
-
-
Save IMoHaMeDHaMdYI/d415166c01543fbdcecd8e80d8b3a859 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_player) | |
val mediaSource = extractMediaSourceFromUri(Uri.parse("asset:///heart_attack.mp3")) | |
val exoPlayer = ExoPlayerFactory.newSimpleInstance( | |
baseContext, DefaultRenderersFactory(baseContext) | |
, DefaultTrackSelector(), | |
DefaultLoadControl() | |
) | |
exoPlayer.apply { | |
// AudioAttributes here from exoplayer package !!! | |
val attr = AudioAttributes.Builder().setUsage(C.USAGE_MEDIA) | |
.setContentType(C.CONTENT_TYPE_MUSIC) | |
.build() | |
// In 2.9.X you don't need to manually handle audio focus :D | |
setAudioAttributes(attr, true) | |
prepare(mediaSource) | |
// THAT IS ALL YOU NEED | |
playWhenReady = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment