Well, I’ve tried to download audios, but there is a problem. When I press the download button, I don’t see anything. So if I go to the app folder I can see an audio file but it’s broken because always have an 600bytes size, and I can’t manually play it.
I wanted to see the progress, so after research I found to do that whit an event. So I’ve tried to show the progress temporaly with toast notifications, but it shows me “97”…“98”… and then no more is happening. If I go to the app folder with my explorer, I see an audio file but broken. And it’s no showing errors! This is the code:
public download(audio: any): void {
this.platform.ready().then(() => {
console.log("Clicked to download: " + audio.id);
let url = `https://api.soundcloud.com/tracks/${audio.id}/download?client_id=${this.SC_CLIENT_ID}`;
let pathToSaveTo: string = '';
if (this.platform.is('android')) {
pathToSaveTo = cordova.file.externalApplicationStorageDirectory + audio.id + '.wav';
let fileTransfer = new Transfer();
fileTransfer.onProgress(this.onProgress);
fileTransfer.download(url, pathToSaveTo)
.then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
let prompt = this.alertCtrl.create({
title: 'Error',
subTitle: error,
buttons: ['Accept']
});
prompt.present();
});
}
});
}
onProgress = (progressEvent: ProgressEvent) : void => {
this.ngZone.run(() => {
if (progressEvent.lengthComputable) {
let progress: any = Math.round((progressEvent.loaded / progressEvent.total) * 100);
console.log(progress);
let toast = this.toastCtrl.create({
message: progress,
duration: 100
});
toast.present();
}
});
}
@Colo9311
I am also trying to download using soundloud url.
When I am trying as you answered above, I am getting response.headers.Location=undefined , so that I am not able download.
Can you provide any solution regarding this?
Of course everybody using this always working process to download SoundCloud tracks. But in reacent days i am using a online web tool to download SoundCloud tracks which is SoundCloud To Mp3.
You’re running into this because SoundCloud audio is not a simple static MP3 file. Most streams are delivered in chunks (HLS / segmented streams), so if you just try to download the URL directly, you’ll often end up with a tiny broken file (like the 600 bytes you’re seeing).
In Ionic / Cordova apps, the usual approaches are:
Use the official SoundCloud API (if the track allows downloads)
Or fetch and merge the stream segments yourself (which is fairly complex on mobile)
If you just want to test or validate the workflow, it can be useful to compare with tools that already handle SoundCloud’s streaming format correctly.
Once you see how a “working” download behaves (file size, headers, duration), it’s much easier to replicate the logic inside an Ionic app or decide whether using the API is the better option.
Hope that helps — SoundCloud downloads are trickier than they look
I tried downloading audios from SoundCloud in my Ionic app, but the files always end up broken (around 600 bytes) even though no errors show. The progress event works partially, but the download never completes. I suspect the SoundCloud API URL I’m using may not allow direct downloads anymore, so I need to use streaming or a proper SDK/API method instead of trying to save the file manually.