1

I'm building an application to play video files of a given folder continuously.

Here's what I used to play a single file by giving the path.

axWindowsMediaPlayer1.URL = @"D:\ShortVideoFolder\Asterix And The Vikings - YouTube.MKV";
            axWindowsMediaPlayer1.settings.autoStart = true;
            axWindowsMediaPlayer1.stretchToFit = true;
            axWindowsMediaPlayer1.settings.setMode("loop", true);

This is working just fine. This is what I did to access all video files in the folder and play those files.

string folderPath = ConfigurationManager.AppSettings["videoFolderPath"]; //Getting folder path saved in App.config file
            string[] fileNames = Directory.GetFiles(@folderPath); //Getting file names of each and every file name in the folder 

        foreach (string file in fileNames)
        {

            axWindowsMediaPlayer1.URL = @"folderPath" + "file";
            axWindowsMediaPlayer1.settings.autoStart = true;

        }

This doesn't play a single file. and doesn't give an error message too. What am I doing wrong here?

ChathurawinD
  • 756
  • 1
  • 13
  • 35
  • In your current example it looks like you're setting the URL of the media player to "folderPathfile" (which is most likely not the path and filename of the file you want to play). I think you probably meant to "combine" the values of the `folderPath` and the `file`, and in that case this should work: `axWindowsMediaPlayer1.URL = Path.Combine(folderPath, file);` – bassfader Sep 05 '18 at 17:27
  • Note though that this will most likely not *"play video files of a given folder continuously"*, IIRC this will rather only start playing the last file found. For playing multiple files in a sequence continuously you'll probably need to create a playlist in the mediaplayer, and set the player to repeat. Maybe have a look at the following related links: [Playlists and Media Items](https://docs.microsoft.com/en-us/windows/desktop/wmp/playlists-and-media-items) / [How to add multiple files to a playlist?](https://stackoverflow.com/questions/14063843/how-to-add-multiple-files-to-a-playlist) – bassfader Sep 05 '18 at 17:35
  • https://stackoverflow.com/questions/14063843/how-to-add-multiple-files-to-a-playlist – Hans Passant Sep 05 '18 at 18:00

1 Answers1

0

first list your files in the director

string[] filePaths = Directory.GetFiles(@"c:\videos\", "*.mp4",
                                     SearchOption.TopDirectoryOnly);

then make loop for each file and play it

foreach(FileInfo file in Files )
{
  str = str + ", " + file.Name;
   axWindowsMediaPlayer1.URL = str;
        axWindowsMediaPlayer1.Ctlcontrols.play();
}
ABDULLAH MAKKI
  • 136
  • 2
  • 8