音频文件的FileSavePicker在Windows Phone 8.1通用应用程序中不工作

本文关键字:1通 应用程序 工作 Phone 文件 FileSavePicker Windows 音频 | 更新日期: 2023-09-27 18:03:01

我尝试了下面的代码,音频文件正在保存,但它显示0字节,我尝试了很多,如果有人知道这个,请帮助我…

WP8.1通用应用程序

Mainpage.cs中的代码:

private async void pick_Click(object sender, RoutedEventArgs e)
        {
            string path = @"Assets'Audio'DeviPrasad.mp3";
            StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            StorageFile file = await folder.GetFileAsync(path);
            var st =await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
            var size = st.Size;
            FileSavePicker savePicker = new FileSavePicker();
            //savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            savePicker.SuggestedSaveFile = file;
            savePicker.FileTypeChoices.Add("MP3", new List<string>() { ".mp3" });
            savePicker.ContinuationData.Add("SourceSound", path);
            savePicker.SuggestedFileName = "DeviPrasad";
            savePicker.PickSaveFileAndContinue();            
        }
internal async void ContinueFileOpenPicker(FileSavePickerContinuationEventArgs e)
        {
            var file = e.File;
            var ff= file.Properties;
            if(file!=null)
            {
                CachedFileManager.DeferUpdates(file);                  
                await FileIO.WriteTextAsync(file, file.Name);                    
                FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
            }
        }

app . example .cs中的代码:

protected async override void OnActivated(IActivatedEventArgs args)
        {
            var root = Window.Current.Content as Frame;
            var mainPage = root.Content as MainPage;
            if (mainPage != null && args is FileSavePickerContinuationEventArgs)
            {
                mainPage.ContinueFileOpenPicker(args as FileSavePickerContinuationEventArgs);
            }
        }

音频文件的FileSavePicker在Windows Phone 8.1通用应用程序中不工作

FileSavePicker不会帮助您将文件的内容写入或复制到目的地。

实际上,我认为你只是简单地从某个地方复制下面的代码,但不确切地知道它在做什么。

await FileIO.WriteTextAsync(file, file.Name);  

这是写东西到文件,似乎是从一个样本,处理txt文件。对于你的情况,我们需要做以下的事情:

  1. 在pick_Click事件中将源文件路径添加到ContinuationData。将代码更改为:savePicker.ContinuationData.Add("SourceSound", file.Path);

  2. 读取ContinueFileOpenPicker中的源文件路径和目标文件,写入如下内容:

        var file = e.File;
        string soundPath = (string)e.ContinuationData["SourceSound"];
        //var ff = file.Properties;
        if (file != null)
        {
            CachedFileManager.DeferUpdates(file);
            StorageFile srcFile = await StorageFile.GetFileFromPathAsync(soundPath);
            await srcFile.CopyAndReplaceAsync(file);
            FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
        }