Для загрузки аудио используйте: Передача файлов
const fileTransfer: FileTransferObject = this.transfer.create();
import { File } from '@ionic-native/file';
constructor(private file: File) { }
download() {
const url = 'https://firebasestorage.googleapis.com/v0/b/helloworld-4e6e6.appspot.com/o/audio%2Fp10_1.mp3?alt=media&token=12bf3400-17a7-4cf9-b862-973707a3164e';
fileTransfer.download(url, this.file.dataDirectory + 'test.mp3').then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
// handle error
});
}
Чтобы проверить, находится ли файл в вашей папке, используйте этот собственный плагин Файл .
Посмотрите на две спецификации плагинов.
Если проблема, задайте здесь, и я отредактирую ответ
Для воспроизведения файла вы должны использовать NATIVE AUDIO .
SO:
this.nativeAudio.preloadSimple('uniqueId1', this.file.dataDirectory + 'test.mp3').then(onSuccess, onError);
И СЕЙЧАС:
this.nativeAudio.play('uniqueId1').then(onSuccess, onError);
// can optionally pass a callback to be called when the file is done playing
this.nativeAudio.play('uniqueId1', () => console.log('uniqueId1 is done playing'));
Полный код:
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer';
import { File } from '@ionic-native/file';
import { NativeAudio } from '@ionic-native/native-audio';
constructor(private transfer: FileTransfer,private file: File,private nativeAudio: NativeAudio) {
const fileTransfer: FileTransferObject = this.transfer.create();
this.download();
this.nativeAudio.preloadSimple('uniqueId1', this.file.dataDirectory + 'test.mp3').then((res) => {
console.log('Mp3 ready');
}, (error) => {
console.log("Some error during load the audio "+error);
});
this.nativeAudio.play('uniqueId1').then((onSuccess)=>{
console.log('Mp3 reproduced ok');
}, (onError)=>{
console.log("Some error during reproduce of the audio "+onError);
});
// can optionally pass a callback to be called when the file is done playing
//this.nativeAudio.play('uniqueId1', () => console.log('uniqueId1 is done playing'));
}
download() {
const url = 'https://firebasestorage.googleapis.com/v0/b/helloworld-4e6e6.appspot.com/o/audio%2Fp10_1.mp3?alt=media&token=12bf3400-17a7-4cf9-b862-973707a3164e';
fileTransfer.download(url, this.file.dataDirectory + 'test.mp3').then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
console.log('Error during download: '+error);
});
}