Pass keyevents from the session to MediaPlayerLifecycleSupport

This commit is contained in:
tzugen 2021-04-21 19:09:57 +02:00
parent 88f6bdb3a9
commit 8bfc5d04ef
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
2 changed files with 13 additions and 1 deletions

View File

@ -183,7 +183,7 @@ public class MediaPlayerLifecycleSupport
context.registerReceiver(headsetEventReceiver, headsetIntentFilter);
}
private void handleKeyEvent(KeyEvent event)
public void handleKeyEvent(KeyEvent event)
{
if (event.getAction() != KeyEvent.ACTION_DOWN || event.getRepeatCount() > 0)
{

View File

@ -71,6 +71,7 @@ public class MediaPlayerService extends Service
private final Lazy<Downloader> downloaderLazy = inject(Downloader.class);
private final Lazy<LocalMediaPlayer> localMediaPlayerLazy = inject(LocalMediaPlayer.class);
private final Lazy<NowPlayingEventDistributor> nowPlayingEventDistributor = inject(NowPlayingEventDistributor.class);
private final Lazy<MediaPlayerLifecycleSupport> mediaPlayerLifecycleSupport = inject(MediaPlayerLifecycleSupport.class);
private LocalMediaPlayer localMediaPlayer;
private Downloader downloader;
@ -893,6 +894,17 @@ public class MediaPlayerService extends Service
super.onSeekTo(pos);
}
@Override
public boolean onMediaButtonEvent(Intent mediaButtonEvent) {
// This probably won't be necessary once we implement more
// of the modern media APIs, like the MediaController etc.
KeyEvent event = (KeyEvent) mediaButtonEvent.getExtras().get("android.intent.extra.KEY_EVENT");
MediaPlayerLifecycleSupport lifecycleSupport = mediaPlayerLifecycleSupport.getValue();
lifecycleSupport.handleKeyEvent(event);
return true;
}
}
);
}