在 MediaElement 控件 WPF 中检索匹配的名称视频

retrieving a matched name video in MediaElement control WPF

我想播放在文本框中输入名称的视频。但它不会播放它播放文件夹中第一个视频的确切视频。请帮忙..

代码

        String vid_name = data.Text;
        string complete_name = vid_name.ToLower() + ".mp4";
        string root = System.IO.Path.GetDirectoryName("D:/abc");
        string[] supportedExtensions = new[] { ".mp4" };
        var files = Directory.GetFiles(Path.Combine(root, "Videos"), "*.*").Where(s => supportedExtensions.Contains(Path.GetExtension(s).ToLower()));

        List<VideosDetail> videos = new List<VideosDetail>();

        VideosDetail id;
        foreach (var file in files)
        {
            id = new VideosDetail()
            {
                Path = file,
                FileName = Path.GetFileName(file),
                Extension = Path.GetExtension(file)
            };


            FileInfo fi = new FileInfo(file);
            id.FileName = fi.Name;
            id.Size = fi.Length;
            videos.Add(id);
             if (id.FileName == complete_name)
            {
          VideoList.ItemsSource = videos; //**Problem comes here
            } 
            else
            {
                MessageBox.Show("no such video is available. ");
            }

        }

由于 videos 是一个列表,所以行

VideoList.ItemsSource = 视频;

指向文件夹中的所有视频(直到与您输入的文件名实际匹配的那个)。因此,不想要的结果。

您可能应该传递列表中视频的索引,例如:

player.Source = 视频[x];

希望对您有所帮助!