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

前端 未结 1 1804
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 00:49

I have a list in which i retrieve multiple mp3 files. Now when i want to add files again, i pick files from picker but they overwrite the previous files in IReadOnlyList fil

相关标签:
1条回答
  • 2021-01-17 01:33

    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();
    
    }
    
    0 讨论(0)
提交回复
热议问题