5

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?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Professor Mustard
  • 191
  • 2
  • 2
  • 4

4 Answers4

1

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.
Karim O.
  • 1,325
  • 6
  • 22
  • 36
1

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

Machta
  • 1,656
  • 2
  • 16
  • 28
  • Well, that would solve the problem, but what happens when I want to turn off repeat? I'd need a mechanism to reload the original playlist and jump back to the exact track and position that I was at when I turned off "repeat". It would be simpler to handle the play state and just store a flag to know whether I'm repeating or not. – Professor Mustard Apr 08 '10 at 11:16
0

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.

usr-local-ΕΨΗΕΛΩΝ
  • 26,101
  • 30
  • 154
  • 305
0

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

James
  • 80,725
  • 18
  • 167
  • 237
  • Yep, in fact that was one of the ways I was thinking of doing it... I just wanted to make sure that there wasn't a "native" way of handling this, before I did a bunch of custom coding. – Professor Mustard Apr 08 '10 at 11:17