如何在xamarin android中下载mp3文件? 异步无效ImgDownload\u单击对象发送方,事件参数e { var webClient=新的webClient; var url=新的Uristream\u url\u soundcloud; 字节[]字节=null; webClient.DownloadProgressChanged+=webClient\u DownloadProgressChanged; dialog=新建进度对话框; dialog.SetProgressStyle ProgressDialogStyle.Horizontal; 对话框。设置标题下载。。。; dialog.SetCancelable false; //对话框.SetButtonCancel,; dialog.SetCanceledOnTouchOutside为false; 对话框。显示; 尝试 { 字节=等待webClient.DownloadDataTaskAsyncurl; } catchTaskCanceledException { Toast.MakeTextthis,任务已取消!,ToastLength.Long; 回来 } 特例a { Toast.MakeTextthis,a.InnerException.Message,ToastLength.Long; dialog.Progress=0; 回来 } Java.IO.File documentsPath=新建Java.IO.FileAndroid.OS.Environment.GetExternalStoragePublicDirectoryAndroid.OS.Environment.DirectoryMusic,MusicDownload; 字符串localFilename=documentsPath+mListData[mPosition].track.title+.mp3; //字符串localPath=System.IO.Path.combinedDocumentsPath,localFilename; Java.IO.File localPath=new Java.IO.FiledocumentsPath,localFilename; dialog.SetTitleDownload完成; //使用writeAsync保存Mp3 //FileStream fs=newfilestreamlocalpath,FileMode.OpenOrCreate; OutputStream fs=新文件OutputStreamLocalPath; 等待fs.WriteAsync字节,0,bytes.Length; 财政司司长:结束; dialog.Progress=0; } void WebClient_DownloadProgressChanged对象发送者,DownloadProgressChangedEventArgs e { dialog.Progress=e.ProgressPercentage; 如果e.ProgressPercentage==100{ //对话框。隐藏; } }

如何在xamarin android中下载mp3文件? 异步无效ImgDownload\u单击对象发送方,事件参数e { var webClient=新的webClient; var url=新的Uristream\u url\u soundcloud; 字节[]字节=null; webClient.DownloadProgressChanged+=webClient\u DownloadProgressChanged; dialog=新建进度对话框; dialog.SetProgressStyle ProgressDialogStyle.Horizontal; 对话框。设置标题下载。。。; dialog.SetCancelable false; //对话框.SetButtonCancel,; dialog.SetCanceledOnTouchOutside为false; 对话框。显示; 尝试 { 字节=等待webClient.DownloadDataTaskAsyncurl; } catchTaskCanceledException { Toast.MakeTextthis,任务已取消!,ToastLength.Long; 回来 } 特例a { Toast.MakeTextthis,a.InnerException.Message,ToastLength.Long; dialog.Progress=0; 回来 } Java.IO.File documentsPath=新建Java.IO.FileAndroid.OS.Environment.GetExternalStoragePublicDirectoryAndroid.OS.Environment.DirectoryMusic,MusicDownload; 字符串localFilename=documentsPath+mListData[mPosition].track.title+.mp3; //字符串localPath=System.IO.Path.combinedDocumentsPath,localFilename; Java.IO.File localPath=new Java.IO.FiledocumentsPath,localFilename; dialog.SetTitleDownload完成; //使用writeAsync保存Mp3 //FileStream fs=newfilestreamlocalpath,FileMode.OpenOrCreate; OutputStream fs=新文件OutputStreamLocalPath; 等待fs.WriteAsync字节,0,bytes.Length; 财政司司长:结束; dialog.Progress=0; } void WebClient_DownloadProgressChanged对象发送者,DownloadProgressChangedEventArgs e { dialog.Progress=e.ProgressPercentage; 如果e.ProgressPercentage==100{ //对话框。隐藏; } },xamarin,xamarin.android,Xamarin,Xamarin.android,我在三星galaxy上测试了该应用程序,但它在FIle.writealBytes处显示错误。 找不到方向 文件夹上的设备是MyAudio。这不是我的音乐。 -我试图将我的音乐替换到我的文档中。它没有显示错误,但我等待了大约3分钟,然后在我的设备上进入mydocument=>看不到任何mp3文件。使用DownloadFileTaskAsync方法尝试类似的操作: 请参阅:路径可能有问题吗? 我的工作是: public async Task<string> SaveFi

我在三星galaxy上测试了该应用程序,但它在FIle.writealBytes处显示错误。 找不到方向

文件夹上的设备是MyAudio。这不是我的音乐。
-我试图将我的音乐替换到我的文档中。它没有显示错误,但我等待了大约3分钟,然后在我的设备上进入mydocument=>看不到任何mp3文件。

使用DownloadFileTaskAsync方法尝试类似的操作:


请参阅:

路径可能有问题吗? 我的工作是:

         public async Task<string> SaveFilePublicStorage(string filename, byte[] fileBody)
         {
            var documentsPath = Android.OS.Environment.ExternalStorageDirectory + "/download/";
            var filePath = Path.Combine(documentsPath, filename);
            File.WriteAllBytes(filePath, fileBody);
            return filePath;
         }

下载完成,但在我的设备上看不到:-文件将出现在作为文档公共存储库的目录中。
         public async Task<string> SaveFilePublicStorage(string filename, byte[] fileBody)
         {
            var documentsPath = Android.OS.Environment.ExternalStorageDirectory + "/download/";
            var filePath = Path.Combine(documentsPath, filename);
            File.WriteAllBytes(filePath, fileBody);
            return filePath;
         }