Media, camera and devices

5 concepts · 15 practice questions

Media playback

Media3 ExoPlayer is the recommended player. A player holds decoders and memory, so release it when the screen stops. Playback that continues in the background, with lock screen controls, runs in a MediaSessionService that owns the player and releases it in onDestroy.

class PlaybackService : MediaSessionService() {
    private var session: MediaSession? = null
    override fun onCreate() {
        super.onCreate()
        session = MediaSession.Builder(this, ExoPlayer.Builder(this).build()).build()
    }
    override fun onGetSession(info: MediaSession.ControllerInfo): MediaSession? = session
    override fun onDestroy() {
        session?.run { player.release(); release() }
        session = null
        super.onDestroy()
    }
}

Also covered

CameraX
Location
Bluetooth Low Energy
Large screens and foldables

Sign in to read the rest and take the 15-question test.

Sign in to continue