react-native-media-notification 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,37 +1,59 @@
1
1
  package com.mediacontrols
2
2
 
3
3
  import android.os.Bundle
4
+ import androidx.media3.common.util.UnstableApi
4
5
  import androidx.media3.session.CommandButton
5
- import androidx.media3.session.CommandButton.ICON_FAST_FORWARD
6
- import androidx.media3.session.CommandButton.ICON_REWIND
6
+ import androidx.media3.session.CommandButton.ICON_NEXT
7
+ import androidx.media3.session.CommandButton.ICON_PREVIOUS
7
8
  import androidx.media3.session.CommandButton.ICON_SHUFFLE_OFF
8
9
  import androidx.media3.session.CommandButton.ICON_SHUFFLE_ON
10
+ import androidx.media3.session.CommandButton.ICON_SKIP_BACK_15
11
+ import androidx.media3.session.CommandButton.ICON_SKIP_FORWARD_15
9
12
  import androidx.media3.session.SessionCommand
10
13
 
11
14
  private const val CUSTOM_COMMAND_REWIND_ACTION_ID = "REWIND_15"
12
15
  private const val CUSTOM_COMMAND_FORWARD_ACTION_ID = "FAST_FWD_15"
16
+ private const val CUSTOM_COMMAND_NEXT_ACTION_ID = "SKIP_TO_NEXT"
17
+ private const val CUSTOM_COMMAND_PREVIOUS_ACTION_ID = "SKIP_TO_PREVIOUS"
13
18
  private const val CUSTOM_COMMAND_SHUFFLE_ON_ACTION_ID = "SHUFFLE_ON"
14
19
  private const val CUSTOM_COMMAND_SHUFFLE_OFF_ACTION_ID = "SHUFFLE_OFF"
15
20
  private const val CUSTOM_COMMAND_REPEAT_ONE_ACTION_ID = "REPEAT_ONE"
16
21
  private const val CUSTOM_COMMAND_REPEAT_ALL_ACTION_ID = "REPEAT_ALL"
17
22
  private const val CUSTOM_COMMAND_REPEAT_OFF_ACTION_ID = "REPEAT_OFF"
18
23
 
24
+ @UnstableApi
19
25
  enum class CustomCommandButton(
20
26
  val customAction: String,
21
27
  val commandButton: CommandButton,
22
28
  ) {
29
+ PREVIOUS(
30
+ customAction = CUSTOM_COMMAND_PREVIOUS_ACTION_ID,
31
+ commandButton = CommandButton.Builder(ICON_PREVIOUS)
32
+ .setDisplayName("Previous")
33
+ .setSessionCommand(SessionCommand(CUSTOM_COMMAND_PREVIOUS_ACTION_ID, Bundle()))
34
+ .build(),
35
+ ),
23
36
  REWIND(
24
37
  customAction = CUSTOM_COMMAND_REWIND_ACTION_ID,
25
- commandButton = CommandButton.Builder(ICON_REWIND)
38
+ commandButton = CommandButton.Builder(ICON_SKIP_BACK_15)
26
39
  .setDisplayName("Rewind")
27
40
  .setSessionCommand(SessionCommand(CUSTOM_COMMAND_REWIND_ACTION_ID, Bundle()))
41
+ .setSlots(CommandButton.SLOT_BACK, CommandButton.SLOT_OVERFLOW)
28
42
  .build(),
29
43
  ),
30
44
  FORWARD(
31
45
  customAction = CUSTOM_COMMAND_FORWARD_ACTION_ID,
32
- commandButton = CommandButton.Builder(ICON_FAST_FORWARD)
46
+ commandButton = CommandButton.Builder(ICON_SKIP_FORWARD_15)
33
47
  .setDisplayName("Forward")
34
48
  .setSessionCommand(SessionCommand(CUSTOM_COMMAND_FORWARD_ACTION_ID, Bundle()))
49
+ .setSlots(CommandButton.SLOT_FORWARD, CommandButton.SLOT_OVERFLOW)
50
+ .build(),
51
+ ),
52
+ NEXT(
53
+ customAction = CUSTOM_COMMAND_NEXT_ACTION_ID,
54
+ commandButton = CommandButton.Builder(ICON_NEXT)
55
+ .setDisplayName("Next")
56
+ .setSessionCommand(SessionCommand(CUSTOM_COMMAND_NEXT_ACTION_ID, Bundle()))
35
57
  .build(),
36
58
  ),
37
59
  SHUFFLE_ON(
@@ -238,6 +238,12 @@ class MediaControlsPlayer(
238
238
 
239
239
  fun getAvailableCustomCommands(): Set<CommandButton> {
240
240
  return mutableSetOf<CommandButton>().apply {
241
+ if (isControlEnabled(Controls.PREVIOUS)) add(CustomCommandButton.PREVIOUS.commandButton)
242
+ if (isControlEnabled(Controls.NEXT)) add(CustomCommandButton.NEXT.commandButton)
243
+
244
+ if (isControlEnabled(Controls.SEEK_BACKWARD)) add(CustomCommandButton.REWIND.commandButton)
245
+ if (isControlEnabled(Controls.SEEK_FORWARD)) add(CustomCommandButton.FORWARD.commandButton)
246
+
241
247
  if(isControlEnabled(Controls.SHUFFLE)) {
242
248
  if (state.shuffleModeEnabled) {
243
249
  add(CustomCommandButton.SHUFFLE_ON.commandButton)
@@ -252,8 +258,6 @@ class MediaControlsPlayer(
252
258
  REPEAT_MODE_ALL -> add(CustomCommandButton.REPEAT_ALL.commandButton)
253
259
  }
254
260
  }
255
- if (isControlEnabled(Controls.SEEK_BACKWARD)) add(CustomCommandButton.REWIND.commandButton)
256
- if (isControlEnabled(Controls.SEEK_FORWARD)) add(CustomCommandButton.FORWARD.commandButton)
257
261
  }
258
262
  }
259
263
 
@@ -189,6 +189,10 @@ class MediaControlsService : MediaSessionService() {
189
189
  }
190
190
  Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
191
191
  }
192
+ CustomCommandButton.PREVIOUS.customAction -> {
193
+ player?.seekToPreviousMediaItem()
194
+ Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
195
+ }
192
196
  CustomCommandButton.FORWARD.customAction -> {
193
197
  player?.seekForward()
194
198
  Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
@@ -197,6 +201,10 @@ class MediaControlsService : MediaSessionService() {
197
201
  player?.seekBack()
198
202
  Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
199
203
  }
204
+ CustomCommandButton.NEXT.customAction -> {
205
+ player?.seekToNextMediaItem()
206
+ Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
207
+ }
200
208
  CustomCommandButton.SHUFFLE_ON.customAction, CustomCommandButton.SHUFFLE_OFF.customAction -> {
201
209
  player?.emitShuffleClicked()
202
210
  Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-media-notification",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Display and manage media style notifications based on react-native-music-control",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",