开发者

Repeat single song in a playlist

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 ha开发者_Go百科ve to devise a "hack" solution, like intercepting the event that fires when the next song is loaded?


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


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜