您好我需要从外部网址下载音频文件并且它可以正常工作,但没有.mp3扩展名,这是播放器识别它所必需的,这是我的代码:
getAudio(token:String,interestPointId:string,link:string, audioId):string{
const downloadManager = new Downloader();
var path:string;
const imageDownloaderId = downloadManager.createDownload({
url:link
});
downloadManager
.start(imageDownloaderId, (progressData: ProgressEventData) => {
console.log(`Progress : ${progressData.value}%`);
console.log(`Current Size : ${progressData.currentSize}%`);
console.log(`Total Size : ${progressData.totalSize}%`);
console.log(`Download Speed in bytes : ${progressData.speed}%`);
})
.then((completed: DownloadEventData) => {
path=completed.path;
console.log(`Image : ${completed.path}`);
})
.catch(error => {
console.log(error.message);
});
return path;
}
只是示例(https://market.nativescript.org/plugins/nativescript-downloader)
中的修改版本目标是下载文件并获取它的路径,而名称应该是~path / idAudio.mp3
欢迎任何帮助,提前谢谢!
答案 0 :(得分:0)
你可以设置fileName和createDownload上的路径没有记录(我忘了)你可以使用interface所以你需要的是以下我也建议你不要试图保存文件到项目根目录,例如~/blah/blah.mp3
,它将在真正的ios设备上失败
downloadManager.createDownload({
url:link
path:somePath,
fileName: 'idAudio.mp3'
}