What to Use to Pick Multiple files (Media files) and retrieve them in a StorageFile collection at custom/desired index?

僤鯓⒐⒋嵵緔 提交于 2019-12-01 14:07:48

PickMultipleFilesAsync will return the files picked during that instance. If you want to add them to a list of previously picked files then add them to a separate list similar to how you add them to mlist (but save the StorageFile not the path. The StorageFile is much more useful).

Here's a modified version of your code which keeps a cumulative fileList:

List<StorageFile> fileList; // don't forget to initialize this somewhere!
private async void addmusicbtn_Click(object sender, RoutedEventArgs e)
{
        var fop = new FileOpenPicker();
        fop.FileTypeFilter.Add(".mp3");
        fop.FileTypeFilter.Add(".mp4");
        fop.FileTypeFilter.Add(".avi");
        fop.FileTypeFilter.Add(".wmv");
        fop.ViewMode = PickerViewMode.List;

        IReadOnlyList<StorageFile> pickedFileList;

        pickedFileList= await fop.PickMultipleFilesAsync();
        // add the picked files to our existing list
        fileList.AddRange(pickedFileList);

        // I'm not sure if you want fileList or pickedFileList here:
        foreach (StorageFile file in fileList)
        {
            mlist.Items.Add(file.Name);
            stream = await file.OpenAsync(FileAccessMode.Read);
            mediafile.SetSource(stream, file.ContentType);
        }
        mediafile.Play();

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!