title: Android ExoPlayer demo: continue playback with screen locked
body: <p>I want to modify the ExoPlayer demo to allow audio playback to continue when the screen gets locked (this should work regardless of whether the media being played is audio or video). Based on some hints (e.g. <a href="https://exoplayer.dev/troubleshooting.html#how-do-i-keep-audio-playing-when-my-app-is-backgrounded" rel="nofollow noreferrer">1</a>, <a href="https://medium.com/google-exoplayer/playback-notifications-with-exoplayer-a2f1a18cf93b" rel="nofollow noreferrer">2</a>) this is what I came up with so far:</p>
  <p><a href="https://github.com/google/ExoPlayer/compare/release-v2...sedubois:background-playback" rel="nofollow noreferrer">https://github.com/google/ExoPlayer/compare/release-v2...sedubois:background-playback</a></p>
  <p>This is directly based on the ExoPlayer demo code, currently in version 2.12.1. It adds a &quot;foreground&quot; permission, registers a service, and creates a notification in that service (according to the documentation this notification is required for background playback). The service is started when initializing the player.</p>
  <p>I can start the player and the demo looks as illustrated below with an audio stream. At this point the notification gets created properly, it shows the player details (title, description, progress bar) and control buttons (see picture below), which work (I can play/pause, restart from the beginning and skip backwards/forwards).</p>
  <p>However the playback still stops when I minimize the application or when I lock the screen by pressing the power button. What is the proper way to make this work?</p>
  <p><a href="https://i.stack.imgur.com/52OaZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/52OaZ.png" alt="ExoPlayer" /></a>
  <a href="https://i.stack.imgur.com/yCszS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yCszS.png" alt="Notification" /></a></p>