Skip to content

Commit

Permalink
feat: wakelock
Browse files Browse the repository at this point in the history
  • Loading branch information
lovegaoshi committed Feb 2, 2024
1 parent af96827 commit 2daba94
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
public abstract class HeadlessJsMediaService extends MediaBrowserServiceCompat implements HeadlessJsTaskEventListener {

private final Set<Integer> mActiveTasks = new CopyOnWriteArraySet<>();
private static @Nullable PowerManager.WakeLock sWakeLock;
public static @Nullable PowerManager.WakeLock sWakeLock;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,10 @@ class MusicService : HeadlessJsMediaService() {
notification = it.notification;
if (it.ongoing) {
if (player.playWhenReady) {
if (sWakeLock?.isHeld != true) {
Timber.tag("RNTP").d("acquiring wakelock")
sWakeLock?.acquire()
}
startForegroundIfNecessary()
}
} else if (shouldStopForeground()) {
Expand All @@ -737,6 +741,10 @@ class MusicService : HeadlessJsMediaService() {
// user's queue is complete. This prevents the service from potentially
// being immediately destroyed once the player finishes playing media.
scope.launch {
if (sWakeLock?.isHeld == true) {
Timber.tag("RNTP").d("releasing wakelock")
sWakeLock?.release()
}
delay(stopForegroundGracePeriod.toLong() * 1000)
if (shouldStopForeground()) {
@Suppress("DEPRECATION")
Expand Down
1 change: 1 addition & 0 deletions example/src/services/SetupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const SetupService = async () => {
await TrackPlayer.updateOptions({
android: {
appKilledPlaybackBehavior: DefaultAudioServiceBehaviour,
stopForegroundGracePeriod: 999999999,
},
// This flag is now deprecated. Please use the above to define playback mode.
// stoppingAppPausesPlayback: true,
Expand Down

0 comments on commit 2daba94

Please sign in to comment.