重复播放列表中的单首歌曲
我有一个播放列表加载到我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试创建一组仅包含一首您想要反复播放的歌曲的新集合。
Try to create a new set with only one song that you want to play over and over again.
这是我的方法。对于我的播放列表,我没有使用 WMPLib 播放列表,而是创建了 IWMPMedia 类型的静态通用列表。这使我能够毫无困难地将歌曲添加到我的播放列表中,因为通用列表会跟踪所有歌曲。因此,要重复播放一首歌曲,我所做的就是获取播放列表中当前播放的歌曲的当前索引,并将其设置为一个整数,然后我做了以下操作:
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:
您无法处理 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?简而言之,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.