SoundCloud에서 오디오를 스트리밍 할 수있는 Ionic 2 앱이 있습니다.soundcloud에서 오디오를 다운로드하는 방법
public loadSelectedTrack(): void {
SC.get('/tracks/' + this.audio.id, {
filter: 'public'
}).then((track) => {
this.soundCloudCurrentTrack = track;
this.playSelectedTrack();
});
}
public playSelectedTrack(): void {
SC.stream('/tracks/' + this.soundCloudCurrentTrack.id).then((player) => {
this.togglePlayPause();
player.on('buffering_start',() => {
console.log('buffering...');
});
player.on('buffering_end',() => {
console.log('party!');
this.audioLoaded = true;
});
player.on('finish',() => {
this.navCtrl.pop();
});
this.player = player;
player.on('time',() => {
this.updateTrackTime();
this.updateTrackPercent();
});
this.saveUserData();
});
}
는 지금, 나는 오디오를 다운로드하는 방법을 알아야하고, 어떻게 장치를 찾을 :
이것은 내가 스트리밍 할 방법이다. 나는 오디오를 다운로드 할 수있는 경우
은 내가 Storage 또는NativeStorage 스토리지 ID를 수 있지만이 할 수있는 최선의 방법 인 경우 나도 몰라, 생각했다. 누군가 그것을 언제든지 했습니까?
편집 : 글쎄, 오디오를 다운로드하려고했지만 문제가 있습니다. 다운로드 버튼을 누르면 아무 것도 볼 수 없습니다. 따라서 앱 폴더로 이동하면 오디오 파일을 볼 수는 있지만 항상 크기가 600 바이트이므로 끊어졌으며 수동으로 재생할 수 없습니다.
나는 진행 상황을보고 싶었 기 때문에 조사를 한 후에 그 사건을 발견했다. 그래서 토스트 알림을 통해 임시 진행 상황을 보여 주려고했지만 "97".. "98"... 그리고 더 이상 진행되지 않습니다. 내 탐색기로 app 폴더로 이동하면 오디오 파일이 보이지만 깨졌습니다. 그리고 그것은 오류를 보여주지 않습니다!
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();
}
});
}
방금 내 코드로 게시물을 편집했습니다. 죄송합니다. –
보고 싶은데, 어떻게하면 오디오를 다운로드하려고하지만 문제가 있는지 추가했습니다. –