I'm trying to make a small C# forms app to grab random music from my music folder and play it in Windows Media Player.
Following basic tutorials I've implemented WMPLib library, like so:
public WMPLib.IWMPMedia temp;
private WMPLib.WindowsMediaPlayer MediaPlayer = new WMPLib.WindowsMediaPlayer();
private WMPLib.IWMPPlaylist playlist;
I have bit lenghty song picking algorythm which finishes with:
playlist = MediaPlayer.playlistCollection.newPlaylist("Random playlist");
playlist.clear();
for ( int i = 0; i < finalTracks.Count; i++ )
{
temp = MediaPlayer.newMedia(finalTracks[i]);
playlist.appendItem(temp);
}
label2.Text = selectedArtist + ", " + finalTracks.Count + " tracks";
Process.Start("wmplayer.exe");
MediaPlayer.currentPlaylist = playlist;
MediaPlayer.controls.play();
However I simply cannot get the program to start playing the picked songs. If I manually go to Playlists in WMP I can see generated playlists, and I can even play them manually, no problem, but the last two lines simply appear to be ignored, no playlist gets selected as current and nothing starts playing.
I've also tried it without Process.Start
line and it doesn't even fire up the WMP. As if the WMPLib.WindowsMediaPlayer
is not linked to the actual WMP program in Windows, more like a seperate control that's not fully implemented, but all tutorials and code examples around the Web use it like I do.
What am I doing wrong?