随机组算法

发布于 2024-10-04 05:09:57 字数 730 浏览 0 评论 0原文

我的音频播放器需要一个“随机播放专辑”算法,就像 foobar2k 中那样。所以问题是:我有一个曲目列表,根据某些标准排序,以便具有相同专辑的曲目全部相邻。现在我需要能够以“随机播放专辑”模式播放播放列表中的歌曲,也就是说,如果下一首曲目来自同一张专辑,则直接播放它,否则,转到下一个随机专辑的第一首曲目。如果用户想播放上一首曲目,请执行相同的操作,但要向后播放。所以问题是:我怎么知道上一张专辑是什么?我真的不想保留播放专辑的历史记录,或保留单独的列表。

目前,我通过为每个轨道提供随机随机播放索引来实现常规随机播放模式,这样我就可以通过查找最大随机播放索引小于当前和最小随机播放索引大于当前的轨道来找到上一个和下一个曲目。但它不适用于随机播放专辑模式。有人可以帮我解决这个问题吗?

示例输入:

Track 1, Album A
Track 2, Album A
Track 1, Album B
Track 2, Album B
Track 3, Album B
Track 1, Album C
Track 2, Album C
Track 3, Album C

假设当前曲目是曲目 1,专辑 A。下一曲目将是曲目 2,专辑 A。下一曲目不是来自同一专辑,因此应选择随机专辑中的第一首曲目,比方说,曲目 1 ,专辑C。我现在所做的是选择下一首曲目,就好像它是常规随机播放模式一样,然后转到其专辑的第一首曲目,从而丢失我来到这张专辑的信息。因此,当用户想要转到上一张专辑时,我不知道如何到达那里。希望这能让问题更清楚。

谢谢。

I need a "shuffle albums" algorithm for my audio player like in foobar2k. So the problem is: I have a list of tracks, sorted according to some criteria so that tracks with same album are all adjacent. Now I need to be able to play songs from the playlist in "shuffle albums" mode, that is, if the next track is from the same album, just play it, otherwise, go to the first track of a next random album. If the user wants to play previous track, do the same thing but backwards. So the question is: how do I know what previous album was? I really don't want to keep a history of played albums, or keep a separate list.

Currently, I implement regular shuffle mode by giving each track random shuffle index, so that I can find previous and next tracks by finding tracks with largest shuffle index smaller than current and smallest shuffle index larger than current. But it doesn't work for shuffle albums mode. Can somebody help me with this?

Sample input:

Track 1, Album A
Track 2, Album A
Track 1, Album B
Track 2, Album B
Track 3, Album B
Track 1, Album C
Track 2, Album C
Track 3, Album C

Let's say current track is Track 1, Album A. Next track will be Track 2, Album A. Next track is not from the same album, so a first track from a random album should be chosen, let's say, Track 1, Album C. What I'm doing now is choosing next track as if it was regular shuffle mode, then going to the first track of its album, thus loosing information from where I came to this album. SO when the user wants to go to the previous album, I have no information how I got there. Hope that makes the question clearer.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月无声 2024-10-11 05:09:57

您可以重复使用随机索引技术来索引专辑。现在,曲目索引是一个(专辑随机索引,曲目位置​​)对。要导航,请增加/减少轨道位置;如果超出范围,则更新专辑索引。

也就是说,您应该重新考虑是否保留历史记录;它可以让你更快地跳回大量专辑。

You can reuse your shuffle index technique to index albums. Now a track index is an (album shuffle index, track pos) pair. To navigate, increment / decrement the track pos; if it goes out of bounds, update the album index.

That said, you should reconsider not keeping an history; it would let you skip back much faster with a large number of albums.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文