capacitor-plugin-playlist 0.7.2 → 0.7.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.
@@ -149,7 +149,7 @@ class PlaylistManager(application: Application) :
149
149
 
150
150
  fun addAllItems(its: List<AudioTrack>?) {
151
151
  val currentItem = currentItem // may be null
152
- audioTracks.addAll(its!!)
152
+ audioTracks.addAll(its.orEmpty())
153
153
  items =
154
154
  audioTracks // not *strictly* needed since they share the reference, but for good measure..
155
155
  currentPosition = audioTracks.indexOf(currentItem)
@@ -212,9 +212,7 @@ class PlaylistManager(application: Application) :
212
212
  }
213
213
 
214
214
  fun clearItems() {
215
- if (playlistHandler != null) {
216
- playlistHandler!!.stop()
217
- }
215
+ playlistHandler?.stop()
218
216
  audioTracks.clear()
219
217
  items = audioTracks
220
218
  currentPosition = INVALID_POSITION
@@ -257,11 +255,16 @@ class PlaylistManager(application: Application) :
257
255
  return playbackSpeed
258
256
  }
259
257
 
260
- fun setPlaybackSpeed(@FloatRange(from = 0.0, to = 1.0) speed: Float) {
261
- playbackSpeed = speed
262
- if (playlistHandler!!.currentMediaPlayer != null && playlistHandler!!.currentMediaPlayer!! is AudioApi) {
263
- Log.i(TAG, "setPlaybackSpeed completing with speed = $speed")
264
- (playlistHandler!!.currentMediaPlayer as AudioApi?)!!.setPlaybackSpeed(playbackSpeed)
258
+ fun setPlaybackSpeed(@FloatRange(from = 0.0625, to = 16.0) speed: Float) {
259
+ val validSpeed = speed.coerceIn(0.0625f, 16.0f)
260
+ playbackSpeed = validSpeed
261
+ playlistHandler?.let { handler ->
262
+ handler.currentMediaPlayer?.let { mediaPlayer ->
263
+ if (mediaPlayer is AudioApi) {
264
+ Log.i(TAG, "setPlaybackSpeed completing with speed = $validSpeed")
265
+ mediaPlayer.setPlaybackSpeed(playbackSpeed)
266
+ }
267
+ }
265
268
  }
266
269
  }
267
270
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-plugin-playlist",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Playlist ",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",