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.
@@ -25,7 +25,13 @@ ext {
25
25
  }
26
26
 
27
27
  apply plugin: 'com.android.library'
28
- apply plugin: 'kotlin-android'
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
- kotlin {
56
- compilerOptions {
57
- jvmTarget = JvmTarget.JVM_21
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 code = id.hashCode()
315
- val seekPosition = (call.getFloat("position", 0f)!! * 1000.0f).toLong()
316
- audioPlayerImpl!!.playlistManager.setCurrentItem(code.toLong())
317
- val handler = audioPlayerImpl!!.playlistManager.playlistHandler
318
- val alreadyPlaying = handler?.currentMediaPlayer?.isPlaying == true
319
- if (!audioPlayerImpl!!.tryResumeVideoHandoffInPlace(seekPosition) && !alreadyPlaying) {
320
- audioPlayerImpl!!.playlistManager.beginPlayback(seekPosition, false)
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
- // alternatively we could search for the item and set the current index to that item.
355
- val code = id.hashCode()
356
- audioPlayerImpl!!.playlistManager.setCurrentItem(code.toLong())
357
-
358
- val seekPosition = (call.getFloat("position", 0f)!! * 1000.0f).toLong()
359
-
360
- audioPlayerImpl!!.playlistManager.beginPlayback(seekPosition, true)
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 options said to start from a specific id, do so.
122
- var idStart: String? = null
123
- if (options.playFromId != null) {
124
- idStart = options.playFromId
125
- }
126
- if (idStart != null && "" != idStart) {
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
- var resolvedPosition = -1
311
- if (trackIndex >= 0 && trackIndex < audioTracks.size) {
312
- resolvedPosition = trackIndex
313
- } else if ("" != trackId) {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-plugin-playlist",
3
- "version": "0.11.1",
3
+ "version": "0.11.4",
4
4
  "description": "Playlist ",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",