Skip to content

Commit

Permalink
fix notification scrubber, resume behavior and title
Browse files Browse the repository at this point in the history
  • Loading branch information
jgitlin-nypr committed Aug 21, 2024
1 parent 72ea037 commit 8a5de76
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,12 @@ public void stop(PluginCall call) {

@PluginMethod
public void setNowPlayingInfo(PluginCall call) throws JSONException, IOException {
String title = call.getData().getString("title", "WNYC");
String artist = call.getString("artist", "");
String album = call.getString("album", "");
String artwork = call.getString("imageUrl", "");

service.setTitle(title);
service.setArtist(artist);
service.setAlbum(album);
service.setArtwork(getImage(artwork));
Expand Down Expand Up @@ -333,6 +335,8 @@ protected void handleOnDestroy() {
super.handleOnDestroy();
}

private boolean resumeOnFocusLossTransient = false;

@Override
public void onAudioFocusChange(int focusChange) {
if (player == null) {
Expand All @@ -343,12 +347,13 @@ public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
player.setVolume(1.0f);
player.play();
if (resumeOnFocusLossTransient) {
player.play();
}
break;
case AudioManager.AUDIOFOCUS_LOSS:
player.pause();
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
resumeOnFocusLossTransient = player.isPlaying();
player.pause();
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
Expand Down Expand Up @@ -393,7 +398,7 @@ public void actionCallback(String action, JSObject data) {
}

private final Set<String> lsactions = Set.of("pause", "play");
private final Set<String> odactions = Set.of("pause", "play", "nexttrack", "previoustrack");
private final Set<String> odactions = Set.of("pause", "play", "nexttrack", "previoustrack","seekto");
public boolean hasActionHandler(String actionName) {
if (isLiveStream) {
return this.lsactions.contains(actionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class RemoteStreamerService extends Service {
private final Map<String, NotificationCompat.Action> notificationActions = new HashMap<>();
private final Map<String, Long> playbackStateActions = new HashMap<>();
private final String[] possibleActions = {"previoustrack", "seekbackward", "play", "pause", "seekforward", "nexttrack", "seekto", "stop"};
final Set<String> possibleCompactViewActions = new HashSet<>(Arrays.asList("previoustrack", "play", "pause", "nexttrack", "stop"));
final Set<String> possibleCompactViewActions = new HashSet<>(Arrays.asList("previoustrack", "play", "pause", "nexttrack", "stop", "seekto"));
private static final int NOTIFICATION_ID = 1;

private int playbackState = PlaybackStateCompat.STATE_NONE;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nypublicradio/capacitor-remote-streamer",
"repository": "git://github.com/nypublicradio/capacitor-remote-streamer.git",
"version": "0.1.9",
"version": "0.1.10",
"description": "Stream remote HLS and MP3 streams on iOS and Android. Capacitor 6.",
"main": "dist/plugin.cjs.js",
"repository": {
Expand Down

0 comments on commit 8a5de76

Please sign in to comment.