当列表视图项被选中时播放歌曲
本文关键字:播放 列表 视图 | 更新日期: 2023-09-27 18:16:41
我想让用户从列表视图中选择一首歌曲并播放它。我试过了:listview.SelectedValuePath
我得到一个错误:Url是空白。我尝试了:listview.SelectedItem.ToString()
我得到一个错误:无效的Url。Listview项文本是文件路径。所以不是这样的。我的完整代码:
FileOpenPicker picker = CreateFilePicker(audioExtensions);
IReadOnlyList<StorageFile> files = await picker.PickMultipleFilesAsync();
if (files != null && files.Count > 0)
{
playlist = new Playlist();
foreach (StorageFile file in files)
{
playlist.Files.Add(file);
StorageFile savedFile =
await playlist.SaveAsAsync(KnownFolders.MusicLibrary,
"Sample",
NameCollisionOption.ReplaceExisting,
PlaylistFormat.WindowsMedia);
this.OutputStatus.Text = savedFile.Name + " was created and saved with "
+ playlist.Files.Count + " files."
+ Environment.NewLine + "At folder: "
+ savedFile.Path;
listview.Items.Add(file.Path.ToString());
}
}
else
{
this.OutputStatus.Text = "No files picked.";
}
My Listview changed:
private void listview_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
media.Source = new Uri(listview.SelectedValuePath);
}
第一个错误(Invalid Url Error)
修复是在ListViewItems添加到ListView:如何在ListView中插入对象类型?
第二个错误(Invalid Source)
修复是获得Content
从选定的ListViewItem:https://stackoverflow.com/a/9800781/2367343