重复播放列表中的单首歌曲

发布于 2024-08-27 19:29:01 字数 350 浏览 15 评论 0原文

我有一个播放列表加载到我的 WMP 实例中,我希望它只循环播放一首歌曲。到目前为止,我在谷歌上搜索到的所有内容都告诉我要这样做:

private AxWindowsMediaPlayer wmp;
wmp.settings.setMode("loop", true);

但是,这似乎只会使整个播放列表重复。我想要的行为是,如果我在播放列表中的歌曲 5 播放时启用“重复”,那么歌曲 5 将在播放结束时自动重复(而不是继续播放歌曲 6)。大多数车载 MP3 播放器已经采用这种方式工作;在我的 C# 程序中是否有一种很好的本机方法来执行此操作,或者我是否必须设计一个“黑客”解决方案,例如拦截加载下一首歌曲时触发的事件?

I have a PlayList loaded into my WMP instance, and I want it to loop just one song. Everything I've Googled up so far tells me to do this:

private AxWindowsMediaPlayer wmp;
wmp.settings.setMode("loop", true);

However, this only seems to make the entire PlayList repeat. The behavior I want is that, if I enable "repeat" when song 5 in the PlayList is playing, then song 5 will keep automatically repeat when it finishes (instead of proceeding to song 6). Most car MP3 players already work this way; is there a nice native way to do this in my C# program, or will I have to devise a "hack" solution, like intercepting the event that fires when the next song is loaded?

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

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

发布评论

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

评论(4

吻风 2024-09-03 19:29:01

尝试创建一组仅包含一首您想要反复播放的歌曲的新集合。

Try to create a new set with only one song that you want to play over and over again.

锦欢 2024-09-03 19:29:01

这是我的方法。对于我的播放列表,我没有使用 WMPLib 播放列表,而是创建了 IWMPMedia 类型的静态通用列表。这使我能够毫无困难地将歌曲添加到我的播放列表中,因为通用列表会跟踪所有歌曲。因此,要重复播放一首歌曲,我所做的就是获取播放列表中当前播放的歌曲的当前索引,并将其设置为一个整数,然后我做了以下操作:

int repeatSongIndex = index;//in this case, our index is the current song playing

player.URL = playlist[repeatSongIndex].sourceURL;//lets have player.URL point to the song object chosen to be repeated to its source url (the directory of the file). 
bool isRepeat = true;//to keep track of whether the repeat option is enabled or not.

Here is my approach. For my playlist, instead of using the WMPLib playlist, I created a static generic list of type IWMPMedia. This enabled me to add songs to my playlist with no difficulty whatsoever in that the generic list kept track of all the songs. So to repeat a song, what I did was I took the current index of the current song playing in the playlist, and set it equal to an integer, then I did something along the lines of:

int repeatSongIndex = index;//in this case, our index is the current song playing

player.URL = playlist[repeatSongIndex].sourceURL;//lets have player.URL point to the song object chosen to be repeated to its source url (the directory of the file). 
bool isRepeat = true;//to keep track of whether the repeat option is enabled or not.
我只土不豪 2024-09-03 19:29:01

您无法处理 PlayStateChange 事件吗并检测何时为当前曲目设置了 MediaEnded 状态并快退?

Could you not handle the PlayStateChange event and detect when the MediaEnded state has been set for the current track and just rewind it?

土豪 2024-09-03 19:29:01

简而言之,WMP 支持重复单个曲目!

因此,您能做的最好的事情就是遵循 Machta 的建议并动态编辑播放列表。例如,当您想要重复播放列表中的单个曲目时,编辑播放列表,使其仅包含该单个曲目并启用循环。不要忘记将旧播放列表保存在其他地方。当用户禁用歌曲循环时,恢复旧的播放列表并将其设置为不重复。

不幸的是,您有一个缺点,即当您更改播放列表时,歌曲可能会从头开始:按照 James 的建议,将播放列表更改安排为 MediaEnded 状态。

这是我能告诉你的最好的了。

The short answer is that WMP does not support repeating a single track!

So the best you can do is follow Machta's suggestion and dynamically edit playlists. For example, when you want to repeat a single track in a playlist edit the playlist such as it has that single track only and enable loop. Don't forget to save somewhere else your old playlist. When the user disables song-loop restore your old playlist and set it to not repeat.

Unfortunately you have the drawback that the song could start from the beginning when you change the playlist: follow James's suggestion and schedule your playlist change to MediaEnded state.

That's the best I can tell you.

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