diff --git a/android/src/main/java/com/doublesymmetry/kotlinaudio/models/AudioItem.kt b/android/src/main/java/com/doublesymmetry/kotlinaudio/models/AudioItem.kt index 517031f77..5a1b2bfb5 100644 --- a/android/src/main/java/com/doublesymmetry/kotlinaudio/models/AudioItem.kt +++ b/android/src/main/java/com/doublesymmetry/kotlinaudio/models/AudioItem.kt @@ -1,13 +1,9 @@ package com.doublesymmetry.kotlinaudio.models -import android.content.Context -import android.graphics.Bitmap import android.net.Uri import android.os.Bundle import androidx.media3.common.MediaItem import androidx.media3.common.MediaMetadata -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext open class AudioItem( open var audioUrl: String, @@ -20,7 +16,7 @@ open class AudioItem( open val options: AudioItemOptions? = null, open val mediaId: String? = null ) { - fun asMediaItem(): MediaItem { + fun toMediaItem(): MediaItem { val extras = Bundle().apply { options?.headers?.let { putSerializable("headers", HashMap(it)) diff --git a/android/src/main/java/com/doublesymmetry/kotlinaudio/players/BaseAudioPlayer.kt b/android/src/main/java/com/doublesymmetry/kotlinaudio/players/BaseAudioPlayer.kt index e9a3390f2..3c4f463d1 100644 --- a/android/src/main/java/com/doublesymmetry/kotlinaudio/players/BaseAudioPlayer.kt +++ b/android/src/main/java/com/doublesymmetry/kotlinaudio/players/BaseAudioPlayer.kt @@ -200,7 +200,7 @@ abstract class BaseAudioPlayer internal constructor( * @param item The [AudioItem] to replace the current one. */ open fun load(item: AudioItem) { - exoPlayer.addMediaItem(item.asMediaItem()) + exoPlayer.addMediaItem(item.toMediaItem()) exoPlayer.prepare() } diff --git a/android/src/main/java/com/doublesymmetry/kotlinaudio/players/QueuedAudioPlayer.kt b/android/src/main/java/com/doublesymmetry/kotlinaudio/players/QueuedAudioPlayer.kt index 8cbd72ab6..dd4bd4022 100644 --- a/android/src/main/java/com/doublesymmetry/kotlinaudio/players/QueuedAudioPlayer.kt +++ b/android/src/main/java/com/doublesymmetry/kotlinaudio/players/QueuedAudioPlayer.kt @@ -5,7 +5,6 @@ import androidx.media3.common.C import androidx.media3.common.IllegalSeekPositionException import androidx.media3.common.MediaItem import androidx.media3.common.Player -import androidx.media3.common.util.UnstableApi import com.doublesymmetry.kotlinaudio.models.* import java.util.* import kotlin.math.max @@ -92,7 +91,7 @@ class QueuedAudioPlayer( if (queue.isEmpty()) { add(item) } else { - exoPlayer.addMediaItem(currentIndex + 1, item.asMediaItem()) + exoPlayer.addMediaItem(currentIndex + 1, item.toMediaItem()) exoPlayer.removeMediaItem(currentIndex) exoPlayer.seekTo(currentIndex, C.TIME_UNSET) exoPlayer.prepare() @@ -113,7 +112,7 @@ class QueuedAudioPlayer( * @param item The [AudioItem] to add. */ fun add(item: AudioItem) { - val mediaSource = item.asMediaItem() + val mediaSource = item.toMediaItem() queue.add(mediaSource) exoPlayer.addMediaItem(mediaSource) exoPlayer.prepare() @@ -134,7 +133,7 @@ class QueuedAudioPlayer( * @param items The [AudioItem]s to add. */ fun add(items: List) { - val mediaItems = items.map { it.asMediaItem() } + val mediaItems = items.map { it.toMediaItem() } queue.addAll(mediaItems) exoPlayer.addMediaItems(mediaItems) exoPlayer.prepare() @@ -147,7 +146,7 @@ class QueuedAudioPlayer( * @param atIndex Index to insert items at, if no items loaded this will not automatically start playback. */ fun add(items: List, atIndex: Int) { - val mediaItems = items.map { (it).asMediaItem() } + val mediaItems = items.map { (it).toMediaItem() } queue.addAll(atIndex, mediaItems) exoPlayer.addMediaItems(atIndex, mediaItems) exoPlayer.prepare() @@ -233,7 +232,7 @@ class QueuedAudioPlayer( * Replaces item at index in queue. */ fun replaceItem(index: Int, item: AudioItem) { - val mediaItem = item.asMediaItem() + val mediaItem = item.toMediaItem() queue[index] = mediaItem exoPlayer.replaceMediaItem(index, mediaItem) } diff --git a/android/src/main/java/com/doublesymmetry/trackplayer/model/Track.kt b/android/src/main/java/com/doublesymmetry/trackplayer/model/Track.kt index 8856ffedb..652725896 100644 --- a/android/src/main/java/com/doublesymmetry/trackplayer/model/Track.kt +++ b/android/src/main/java/com/doublesymmetry/trackplayer/model/Track.kt @@ -32,8 +32,18 @@ class Track } fun toAudioItem(): TrackAudioItem { - return TrackAudioItem(this, type, uri.toString(), artist, title, album, artwork.toString(), duration, - AudioItemOptions(headers, userAgent, resourceId), mediaId) + return TrackAudioItem( + track = this, + type = type, + audioUrl = uri.toString(), + artist = artist, + title = title, + albumTitle = album, + artwork = artwork.toString(), + duration = duration, + options = AudioItemOptions(headers, userAgent, resourceId), + mediaId = mediaId + ) } init {