Hi, I use this code succesfully to record an audio note within an Android app:
(...)
import { Media, MediaObject } from '@ionic-native/media';
import { File } from '@ionic-native/file';
(...)
@IonicPage()
@Component({
selector: 'page-modal-add',
templateUrl: 'modal-add.html',
providers: [ File ]
})
export class ModalAddPage {
private activityForm: FormGroup;
data: any;
todayDate: string;
constructor(
public navParams: NavParams,
private view: ViewController,
private navCtrl: NavController,
private formBuilder: FormBuilder,
public database: DatabaseProvider,
public alertCtrl: AlertController,
private media: Media,
private file: File
) {
(...)
}
startRecordingAudio() {
try {
this.file.createDir(this.file.dataDirectory, 'Notes', false);
const audioFile: MediaObject = this.media.create('./audioFile.mp3');
this.showAlert(audioFile, 'Info', 'Start recording!');
audioFile.startRecord();
}
catch (e) {
this.showAlert(null, 'Error', 'Could not start recording.');
}
}
showAlert(fileHandler, type, message) {
let alert = this.alertCtrl.create({
title: type,
subTitle: message,
buttons: [{
text: 'Stop recording',
handler: () => {
fileHandler.stopRecord();
}
}]
});
alert.present();
}
closeModal(){
(...)
}
}
And it creates an audioFile.mp3 file at /storage/emulated/0 path.
I now need to create the file inside a
/Notes/audio/
folder, not inside /storage/emulated/0 one as it does now.
I tried to use
const audioFile: MediaObject = this.media.create( this.file.dataDirectory + './audioFile.mp3');
with no luck (it creates a 3gp file with an arbitrary name, instead).
How can I accomplish it?
Thank you in advance.