簡體   English   中英

FileSavePicker for Audio文件在Windows Phone 8.1 Universal Apps中不起作用

[英]FileSavePicker for Audio file is not working in Windows Phone 8.1 Universal Apps

我嘗試了以下代碼,音頻文件正在保存,但顯示為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.xaml.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不會幫助您將文件內容寫入或復制到目標位置。

實際上,我認為您只是從某個地方復制以下代碼,但不完全知道它在做什么。

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); } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM