我想播放在文本框中输入名称的视频。但它没有播放它播放文件夹中第一个视频的确切视频。任何帮助请... ..
代码
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. ");
}
}
答案 0 :(得分:0)
由于视频是列表,行
VideoList.ItemsSource = videos;
指向文件夹中的所有视频(最多与您输入的文件名匹配的视频)。因此,不需要的结果。
您应该传递列表中视频的索引,例如:
player.Source = videos [x];
希望这有帮助!