0

我正在构建一个应用程序来连续播放给定文件夹的视频文件。

这是我过去通过给出路径来播放单个文件的内容。

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

这工作得很好。这就是我访问文件夹中所有视频文件并播放这些文件的方法。

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;

        }

这不会播放单个文件。并且也不给出错误消息。我在这里做错了什么?

4

1 回答 1

0

首先在director中列出你的文件

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

然后为每个文件循环播放并播放

foreach(FileInfo file in Files )
{
  str = str + ", " + file.Name;
   axWindowsMediaPlayer1.URL = str;
        axWindowsMediaPlayer1.Ctlcontrols.play();
}
于 2021-03-03T20:39:53.453 回答