capacitor-plugin-playlist 0.11.1 → 0.11.4
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/android/build.gradle +13 -5
- package/android/src/main/java/org/dwbn/plugins/playlist/PlaylistPlugin.kt +17 -14
- package/android/src/main/java/org/dwbn/plugins/playlist/data/AudioTrack.kt +7 -6
- package/android/src/main/java/org/dwbn/plugins/playlist/manager/PlaylistManager.kt +19 -27
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -25,7 +25,13 @@ ext {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
apply plugin: 'com.android.library'
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
// AGP 9+ (consuming apps) provides built-in Kotlin; applying kotlin-android there fails.
|
|
30
|
+
// Standalone `./gradlew test` (CI) still uses AGP 8.x from this module's buildscript.
|
|
31
|
+
def agpMajorVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
|
|
32
|
+
if (agpMajorVersion < 9) {
|
|
33
|
+
apply plugin: 'kotlin-android'
|
|
34
|
+
}
|
|
29
35
|
|
|
30
36
|
android {
|
|
31
37
|
namespace = "org.dwbn.plugins.playlist"
|
|
@@ -40,7 +46,7 @@ android {
|
|
|
40
46
|
buildTypes {
|
|
41
47
|
release {
|
|
42
48
|
minifyEnabled false
|
|
43
|
-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
49
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
44
50
|
}
|
|
45
51
|
}
|
|
46
52
|
lintOptions {
|
|
@@ -52,9 +58,11 @@ android {
|
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
if (agpMajorVersion < 9) {
|
|
62
|
+
kotlin {
|
|
63
|
+
compilerOptions {
|
|
64
|
+
jvmTarget = JvmTarget.JVM_21
|
|
65
|
+
}
|
|
58
66
|
}
|
|
59
67
|
}
|
|
60
68
|
|
|
@@ -311,13 +311,16 @@ public class PlaylistPlugin : Plugin(), OnStatusReportListener {
|
|
|
311
311
|
Handler(Looper.getMainLooper()).post {
|
|
312
312
|
val id: String = call.getString("id")!!
|
|
313
313
|
if ("" != id) {
|
|
314
|
-
val
|
|
315
|
-
val
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
314
|
+
val playlistManager = audioPlayerImpl!!.playlistManager
|
|
315
|
+
val position = playlistManager.findTrackPosition(id)
|
|
316
|
+
if (position >= 0) {
|
|
317
|
+
val seekPosition = (call.getFloat("position", 0f)!! * 1000.0f).toLong()
|
|
318
|
+
playlistManager.currentPosition = position
|
|
319
|
+
val handler = playlistManager.playlistHandler
|
|
320
|
+
val alreadyPlaying = handler?.currentMediaPlayer?.isPlaying == true
|
|
321
|
+
if (!audioPlayerImpl!!.tryResumeVideoHandoffInPlace(seekPosition) && !alreadyPlaying) {
|
|
322
|
+
playlistManager.beginPlayback(seekPosition, false)
|
|
323
|
+
}
|
|
321
324
|
}
|
|
322
325
|
}
|
|
323
326
|
|
|
@@ -351,13 +354,13 @@ public class PlaylistPlugin : Plugin(), OnStatusReportListener {
|
|
|
351
354
|
Handler(Looper.getMainLooper()).post {
|
|
352
355
|
val id: String = call.getString("id")!!
|
|
353
356
|
if ("" != id) {
|
|
354
|
-
|
|
355
|
-
val
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
357
|
+
val playlistManager = audioPlayerImpl!!.playlistManager
|
|
358
|
+
val position = playlistManager.findTrackPosition(id)
|
|
359
|
+
if (position >= 0) {
|
|
360
|
+
val seekPosition = (call.getFloat("position", 0f)!! * 1000.0f).toLong()
|
|
361
|
+
playlistManager.currentPosition = position
|
|
362
|
+
playlistManager.beginPlayback(seekPosition, true)
|
|
363
|
+
}
|
|
361
364
|
}
|
|
362
365
|
call.resolve()
|
|
363
366
|
|
|
@@ -5,8 +5,15 @@ import com.devbrackets.android.playlistcore.api.PlaylistItem
|
|
|
5
5
|
import com.devbrackets.android.playlistcore.manager.BasePlaylistManager
|
|
6
6
|
import org.json.JSONException
|
|
7
7
|
import org.json.JSONObject
|
|
8
|
+
import java.util.concurrent.atomic.AtomicLong
|
|
8
9
|
|
|
9
10
|
class AudioTrack (private val config: JSONObject) : PlaylistItem {
|
|
11
|
+
companion object {
|
|
12
|
+
private val nextPlaylistId = AtomicLong(1)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
override val id: Long = nextPlaylistId.getAndIncrement()
|
|
16
|
+
|
|
10
17
|
var bufferPercentFloat = 0f
|
|
11
18
|
set(buff) {
|
|
12
19
|
// There is a bug in MediaProgress where if bufferPercent == 100 it sets bufferPercentFloat
|
|
@@ -38,12 +45,6 @@ class AudioTrack (private val config: JSONObject) : PlaylistItem {
|
|
|
38
45
|
return info
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
override val id: Long
|
|
42
|
-
get() =
|
|
43
|
-
if (trackId == null) {
|
|
44
|
-
0
|
|
45
|
-
} else trackId.hashCode().toLong()
|
|
46
|
-
|
|
47
48
|
val isStream: Boolean
|
|
48
49
|
get() = config.optBoolean("isStream", false)
|
|
49
50
|
|
|
@@ -104,28 +104,22 @@ class PlaylistManager(application: Application) :
|
|
|
104
104
|
* List management
|
|
105
105
|
*/
|
|
106
106
|
fun setAllItems(items: List<AudioTrack>?, options: PlaylistItemOptions) {
|
|
107
|
+
val seekStart = when {
|
|
108
|
+
options.playFromPosition >= 0 -> options.playFromPosition
|
|
109
|
+
options.retainPosition -> currentProgress?.position ?: 0
|
|
110
|
+
else -> 0
|
|
111
|
+
}
|
|
112
|
+
|
|
107
113
|
clearItems()
|
|
108
114
|
addAllItems(items)
|
|
109
115
|
currentPosition = 0
|
|
110
|
-
// If the options said to start from a specific position, do so.
|
|
111
|
-
var seekStart: Long = 0
|
|
112
|
-
if (options.playFromPosition > 0) {
|
|
113
|
-
seekStart = options.playFromPosition
|
|
114
|
-
} else if (options.retainPosition) {
|
|
115
|
-
val progress = currentProgress
|
|
116
|
-
if (progress != null) {
|
|
117
|
-
seekStart = progress.position
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
116
|
|
|
121
|
-
// If the
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
val code = idStart.hashCode()
|
|
128
|
-
setCurrentItem(code.toLong())
|
|
117
|
+
// If the requested id exists, start there; otherwise keep the first track.
|
|
118
|
+
options.playFromId?.let { trackId ->
|
|
119
|
+
val position = findTrackPosition(trackId)
|
|
120
|
+
if (position != INVALID_POSITION) {
|
|
121
|
+
currentPosition = position
|
|
122
|
+
}
|
|
129
123
|
}
|
|
130
124
|
|
|
131
125
|
// We assume that if the playlist is fully loaded in one go,
|
|
@@ -307,18 +301,16 @@ class PlaylistManager(application: Application) :
|
|
|
307
301
|
}
|
|
308
302
|
|
|
309
303
|
private fun resolveItemPosition(trackIndex: Int, trackId: String): Int {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
val itemPos = getPositionForItem(trackId.hashCode().toLong())
|
|
315
|
-
if (itemPos != INVALID_POSITION) {
|
|
316
|
-
resolvedPosition = itemPos
|
|
317
|
-
}
|
|
304
|
+
return when {
|
|
305
|
+
trackIndex in audioTracks.indices -> trackIndex
|
|
306
|
+
trackId.isNotEmpty() -> findTrackPosition(trackId)
|
|
307
|
+
else -> INVALID_POSITION
|
|
318
308
|
}
|
|
319
|
-
return resolvedPosition
|
|
320
309
|
}
|
|
321
310
|
|
|
311
|
+
internal fun findTrackPosition(trackId: String): Int =
|
|
312
|
+
audioTracks.indexOfFirst { it.trackId == trackId }
|
|
313
|
+
|
|
322
314
|
fun getVolumeLeft(): Float {
|
|
323
315
|
return volumeLeft
|
|
324
316
|
}
|