Skip to content

Commit

Permalink
multiqueue: Play playlist content instead of endpoint
Browse files Browse the repository at this point in the history
* Before, clicking on a playlist song starts a radio-like
   queue, instead of loading the playlist content. Correct
   this design flaw.
* fixes #37
  • Loading branch information
mikooomich committed Sep 8, 2024
1 parent 3952080 commit c151293
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.dd3boh.outertune.extensions.toMediaItem
import com.dd3boh.outertune.models.toMediaMetadata
import com.dd3boh.outertune.playback.ExoDownloadService
import com.dd3boh.outertune.playback.PlayerConnection.Companion.queueBoard
import com.dd3boh.outertune.playback.queues.ListQueue
import com.dd3boh.outertune.playback.queues.YouTubeQueue
import com.dd3boh.outertune.ui.component.DefaultDialog
import com.dd3boh.outertune.ui.component.DownloadGridMenu
Expand Down Expand Up @@ -261,7 +262,14 @@ fun YouTubePlaylistMenu(
title = R.string.play
) {
println("Play: ${it.playlistId}, ${it.params}")
playerConnection.playQueue(YouTubeQueue(it))
playerConnection.playQueue(
ListQueue(
playlistId = playlist.playEndpoint!!.playlistId,
title = playlist.title,
items = songs.map { it.toMediaMetadata() },
)
)

onDismiss()
}
}
Expand All @@ -272,7 +280,13 @@ fun YouTubePlaylistMenu(
title = R.string.shuffle
) {
println("Shuffle: id: ${shuffleEndpoint.playlistId}, params: ${shuffleEndpoint.params}")
playerConnection.playQueue(YouTubeQueue(shuffleEndpoint))
playerConnection.playQueue(
ListQueue(
playlistId = playlist.playEndpoint!!.playlistId,
title = playlist.title,
items = songs.map { it.toMediaMetadata() }.shuffled(),
)
)
onDismiss()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
Expand Down Expand Up @@ -236,10 +237,10 @@ fun ArtistScreen(
)
}

items(
itemsIndexed(
items = librarySongs,
key = { "local_${it.id}" }
) { song ->
key = { _, item -> item.hashCode() }
) { index, song ->
SwipeToQueueBox(
item = song.toMediaItem(),
content = {
Expand Down Expand Up @@ -270,19 +271,13 @@ fun ArtistScreen(
.combinedClickable {
if (song.id == mediaMetadata?.id) {
playerConnection.player.togglePlayPause()
} else if (song.song.isLocal) {
} else {
playerConnection.playQueue(
ListQueue(
title = "Library: ${artistPage.artist.title}",
items = librarySongs.filter { it.song.isLocal } .toList().shuffled().map { it.toMediaMetadata() }
)
)
} else {
playerConnection.playQueue(
YouTubeQueue(
WatchEndpoint(
videoId = song.id
), song.toMediaMetadata()
items = librarySongs.filter { it.song.isLocal }.toList()
.shuffled().map { it.toMediaMetadata() },
startIndex = index
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.ClickableText
Expand Down Expand Up @@ -87,7 +87,7 @@ import com.dd3boh.outertune.extensions.toMediaItem
import com.dd3boh.outertune.extensions.togglePlayPause
import com.dd3boh.outertune.models.toMediaMetadata
import com.dd3boh.outertune.playback.ExoDownloadService
import com.dd3boh.outertune.playback.queues.YouTubeQueue
import com.dd3boh.outertune.playback.queues.ListQueue
import com.dd3boh.outertune.ui.component.AutoResizeText
import com.dd3boh.outertune.ui.component.DefaultDialog
import com.dd3boh.outertune.ui.component.FontSizeRange
Expand All @@ -106,7 +106,6 @@ import com.dd3boh.outertune.ui.utils.ItemWrapper
import com.dd3boh.outertune.ui.utils.backToMain
import com.dd3boh.outertune.viewmodels.OnlinePlaylistViewModel
import com.zionhuang.innertube.models.SongItem
import com.zionhuang.innertube.models.WatchEndpoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -442,7 +441,13 @@ fun OnlinePlaylistScreen(
playlist.playEndpoint?.let { playEndpoint ->
Button(
onClick = {
playerConnection.playQueue(YouTubeQueue(playEndpoint))
playerConnection.playQueue(
ListQueue(
playlistId = playlist.playEndpoint!!.playlistId,
title = playlist.title,
items = songs.map { it.toMediaMetadata() },
)
)
},
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
modifier = Modifier.weight(1f)
Expand All @@ -457,10 +462,16 @@ fun OnlinePlaylistScreen(
}
}

playlist.shuffleEndpoint?.let { shuffleEndpoint ->
playlist.shuffleEndpoint?.let {
OutlinedButton(
onClick = {
playerConnection.playQueue(YouTubeQueue(shuffleEndpoint))
playerConnection.playQueue(
ListQueue(
playlistId = playlist.playEndpoint!!.playlistId,
title = playlist.title,
items = songs.map { it.toMediaMetadata() }.shuffled(),
)
)
},
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
modifier = Modifier.weight(1f)
Expand Down Expand Up @@ -492,9 +503,9 @@ fun OnlinePlaylistScreen(
}
}

items(
itemsIndexed(
items = wrappedSongs
) { song ->
) { index, song ->
SwipeToQueueBox(
item = song.item.toMediaItem(),
content = {
Expand Down Expand Up @@ -528,9 +539,11 @@ fun OnlinePlaylistScreen(
playerConnection.player.togglePlayPause()
} else {
playerConnection.playQueue(
YouTubeQueue(
song.item.endpoint ?: WatchEndpoint(videoId = song.item.id),
song.item.toMediaMetadata()
ListQueue(
playlistId = playlist.id,
title = playlist.title,
items = songs.map { it.toMediaMetadata() },
startIndex = index
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import com.dd3boh.outertune.constants.SearchFilterHeight
import com.dd3boh.outertune.extensions.toMediaItem
import com.dd3boh.outertune.extensions.togglePlayPause
import com.dd3boh.outertune.models.toMediaMetadata
import com.dd3boh.outertune.playback.queues.ListQueue
import com.dd3boh.outertune.playback.queues.YouTubeQueue
import com.dd3boh.outertune.ui.component.ChipsRow
import com.dd3boh.outertune.ui.component.EmptyPlaceholder
Expand Down Expand Up @@ -161,15 +160,6 @@ fun OnlineSearchResult(
is SongItem -> {
if (item.id == mediaMetadata?.id) {
playerConnection.player.togglePlayPause()
} else if (item.id.startsWith("LA")) {
playerConnection.playQueue(
ListQueue(
title = "Search",
items = listOf(item.toMediaMetadata())
),
replace = true,
title = "Search",
)
} else {
playerConnection.playQueue(
YouTubeQueue(
Expand Down

0 comments on commit c151293

Please sign in to comment.