capacitor-plugin-playlist 0.10.10 → 0.11.0
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.
- package/README.md +11 -11
- package/android/src/main/AndroidManifest.xml +11 -2
- package/android/src/main/java/org/dwbn/plugins/playlist/App.kt +2 -15
- package/android/src/main/java/org/dwbn/plugins/playlist/PlaylistPlugin.kt +1 -1
- package/android/src/main/java/org/dwbn/plugins/playlist/PlaylistRuntime.kt +16 -0
- package/android/src/main/java/org/dwbn/plugins/playlist/RmxAudioPlayer.java +7 -9
- package/android/src/main/java/org/dwbn/plugins/playlist/service/MediaService.kt +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ Requires **Capacitor 8+** (peer dependency `@capacitor/core >= 8.0.0`).
|
|
|
49
49
|
|
|
50
50
|
### Background audio
|
|
51
51
|
|
|
52
|
-
- Android: foreground media service with `WAKE_LOCK` and `FOREGROUND_SERVICE_MEDIA_PLAYBACK` (Android 14+)
|
|
52
|
+
- Android: foreground media service with `WAKE_LOCK`, `FOREGROUND_SERVICE`, and `FOREGROUND_SERVICE_MEDIA_PLAYBACK` (Android 14+)
|
|
53
53
|
- iOS: `UIBackgroundModes` → `audio`
|
|
54
54
|
- Position events throttled while WebView is backgrounded; one live snapshot emitted on foreground resume (0.9.1+)
|
|
55
55
|
|
|
@@ -132,16 +132,16 @@ Add to `angular.json` → architect → build → options → scripts:
|
|
|
132
132
|
|
|
133
133
|
#### AndroidManifest.xml
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
135
|
+
From **0.11.0**, the plugin library manifest merges the media playback service and required permissions into your app automatically:
|
|
136
|
+
|
|
137
|
+
- `android.permission.WAKE_LOCK`
|
|
138
|
+
- `android.permission.FOREGROUND_SERVICE`
|
|
139
|
+
- `android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK`
|
|
140
|
+
- `org.dwbn.plugins.playlist.service.MediaService` (`exported="false"`, `foregroundServiceType="mediaPlayback"`)
|
|
141
|
+
|
|
142
|
+
After upgrading, run `npx cap sync android`. You do **not** need to copy these entries into your host `AndroidManifest.xml` unless you want to override plugin defaults.
|
|
143
|
+
|
|
144
|
+
Keep your application's existing Android `Application` class. The legacy `org.dwbn.plugins.playlist.App` class remains available for compatibility, but it is no longer required — remove `android:name="org.dwbn.plugins.playlist.App"` from `<application>` when upgrading from older setups.
|
|
145
145
|
|
|
146
146
|
#### Gradle 9+
|
|
147
147
|
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
|
|
2
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
-
|
|
2
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
|
+
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
4
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
5
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
|
6
|
+
|
|
7
|
+
<application>
|
|
8
|
+
<service
|
|
9
|
+
android:name="org.dwbn.plugins.playlist.service.MediaService"
|
|
10
|
+
android:exported="false"
|
|
11
|
+
android:foregroundServiceType="mediaPlayback" />
|
|
12
|
+
</application>
|
|
4
13
|
</manifest>
|
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
package org.dwbn.plugins.playlist
|
|
2
2
|
|
|
3
3
|
import android.app.Application
|
|
4
|
-
import org.dwbn.plugins.playlist.manager.PlaylistManager
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
val playlistManager get() = _playlistManager
|
|
9
|
-
|
|
10
|
-
fun resetPlaylistManager() {
|
|
11
|
-
_playlistManager = PlaylistManager(this)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
override fun onCreate() {
|
|
15
|
-
resetPlaylistManager()
|
|
16
|
-
super.onCreate()
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
}
|
|
5
|
+
@Deprecated("No longer required; use your app's existing Application class")
|
|
6
|
+
class App : Application()
|
|
@@ -22,7 +22,7 @@ public class PlaylistPlugin : Plugin(), OnStatusReportListener {
|
|
|
22
22
|
private var isWebViewActive = true
|
|
23
23
|
|
|
24
24
|
override fun load() {
|
|
25
|
-
audioPlayerImpl = RmxAudioPlayer(this,
|
|
25
|
+
audioPlayerImpl = RmxAudioPlayer(this, context.applicationContext)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
@PluginMethod
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package org.dwbn.plugins.playlist
|
|
2
|
+
|
|
3
|
+
import android.app.Application
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import org.dwbn.plugins.playlist.manager.PlaylistManager
|
|
6
|
+
|
|
7
|
+
object PlaylistRuntime {
|
|
8
|
+
private var playlistManager: PlaylistManager? = null
|
|
9
|
+
|
|
10
|
+
@JvmStatic
|
|
11
|
+
fun getPlaylistManager(context: Context): PlaylistManager = synchronized(this) {
|
|
12
|
+
playlistManager ?: PlaylistManager(context.applicationContext as Application).also {
|
|
13
|
+
playlistManager = it
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package org.dwbn.plugins.playlist;
|
|
2
2
|
|
|
3
|
+
import android.content.Context;
|
|
3
4
|
import android.util.Log;
|
|
4
5
|
|
|
5
6
|
import androidx.annotation.NonNull;
|
|
@@ -39,16 +40,16 @@ public class RmxAudioPlayer implements PlaybackStatusListener<AudioTrack>,
|
|
|
39
40
|
// It would be used to switch between playlists. I guess we could
|
|
40
41
|
// support that in the future, might be cool.
|
|
41
42
|
private static final int PLAYLIST_ID = 32;
|
|
42
|
-
private PlaylistManager playlistManager;
|
|
43
|
+
private final PlaylistManager playlistManager;
|
|
43
44
|
private final OnStatusReportListener statusListener;
|
|
44
45
|
|
|
45
46
|
private int lastBufferPercent = 0;
|
|
46
47
|
private long lastDuration = 0;
|
|
47
48
|
private boolean trackLoaded = false;
|
|
48
49
|
private boolean resetStreamOnPause = true;
|
|
49
|
-
private final
|
|
50
|
+
private final Context context;
|
|
50
51
|
|
|
51
|
-
public RmxAudioPlayer(@NonNull OnStatusReportListener statusListener,
|
|
52
|
+
public RmxAudioPlayer(@NonNull OnStatusReportListener statusListener, @NonNull Context context) {
|
|
52
53
|
// AudioPlayerPlugin and RmxAudioPlayer are separate classes in order to increase
|
|
53
54
|
// the portability of this code.
|
|
54
55
|
// Because AudioPlayerPlugin itself holds a strong reference to this class,
|
|
@@ -56,10 +57,9 @@ public class RmxAudioPlayer implements PlaybackStatusListener<AudioTrack>,
|
|
|
56
57
|
// but these two objects will always live together (And the plugin couldn't function
|
|
57
58
|
// at all if this one gets garbage collected).
|
|
58
59
|
this.statusListener = statusListener;
|
|
59
|
-
this.
|
|
60
|
+
this.context = context.getApplicationContext();
|
|
61
|
+
this.playlistManager = PlaylistRuntime.getPlaylistManager(this.context);
|
|
60
62
|
|
|
61
|
-
app.resetPlaylistManager();
|
|
62
|
-
getPlaylistManager();
|
|
63
63
|
playlistManager.setId(PLAYLIST_ID);
|
|
64
64
|
playlistManager.setPlaybackStatusListener(this);
|
|
65
65
|
playlistManager.setOnErrorListener(this);
|
|
@@ -67,7 +67,6 @@ public class RmxAudioPlayer implements PlaybackStatusListener<AudioTrack>,
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
public PlaylistManager getPlaylistManager() {
|
|
70
|
-
playlistManager = app.getPlaylistManager();
|
|
71
70
|
return playlistManager;
|
|
72
71
|
}
|
|
73
72
|
|
|
@@ -81,7 +80,7 @@ public class RmxAudioPlayer implements PlaybackStatusListener<AudioTrack>,
|
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
public void setOptions(JSONObject val) {
|
|
84
|
-
Options options = new Options(
|
|
83
|
+
Options options = new Options(context, val);
|
|
85
84
|
getPlaylistManager().setOptions(options);
|
|
86
85
|
}
|
|
87
86
|
|
|
@@ -412,7 +411,6 @@ public class RmxAudioPlayer implements PlaybackStatusListener<AudioTrack>,
|
|
|
412
411
|
|
|
413
412
|
public void resume() {
|
|
414
413
|
Log.i(TAG, "Resumed, wiring up event listeners");
|
|
415
|
-
getPlaylistManager();
|
|
416
414
|
registerPlaylistListeners();
|
|
417
415
|
//Makes sure to retrieve the current playback information
|
|
418
416
|
updateCurrentPlaybackInformation();
|
|
@@ -8,7 +8,7 @@ import android.os.Build
|
|
|
8
8
|
import android.util.Log
|
|
9
9
|
import com.devbrackets.android.playlistcore.components.playlisthandler.PlaylistHandler
|
|
10
10
|
import com.devbrackets.android.playlistcore.service.BasePlaylistService
|
|
11
|
-
import org.dwbn.plugins.playlist.
|
|
11
|
+
import org.dwbn.plugins.playlist.PlaylistRuntime
|
|
12
12
|
import org.dwbn.plugins.playlist.data.AudioTrack
|
|
13
13
|
import org.dwbn.plugins.playlist.manager.PlaylistManager
|
|
14
14
|
import org.dwbn.plugins.playlist.playlist.AudioApi
|
|
@@ -97,7 +97,7 @@ class MediaService : BasePlaylistService<AudioTrack, PlaylistManager>() {
|
|
|
97
97
|
fun isRunningInForeground(): Boolean = inForeground
|
|
98
98
|
|
|
99
99
|
override val playlistManager: PlaylistManager
|
|
100
|
-
get() = (applicationContext
|
|
100
|
+
get() = PlaylistRuntime.getPlaylistManager(applicationContext)
|
|
101
101
|
|
|
102
102
|
override fun newPlaylistHandler(): PlaylistHandler<AudioTrack> {
|
|
103
103
|
val imageProvider = MediaImageProvider(applicationContext, object : OnImageUpdatedListener {
|