I am trying to record audio and save it to a specific folder and make some playback functionality with that saved audio. i could record and save it, but i could not save that audio file to a directory and could not able to make playback could someone help me
import { Component } from '@angular/core';
import {File} from 'ionic-native';
import { NavController,AlertController } from 'ionic-angular';
import { MediaPlugin } from 'ionic-native';
declare var cordova;
declare var cordovaFile;
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
media: MediaPlugin = new MediaPlugin('../Library/NoCloud/recording.wav');
constructor(public navCtrl: NavController,
public alertCtrl: AlertController) {
}
createFolder(){
console.log('inside folder creation');
File.createDir(cordova.file.externalRootDirectory, "Audio_folder", false)
.then(function (success) {
console.log("folder creation sucess",success);
}, function (error) {
console.log("folder creation error",error);
});
}
startRecording() {
try {
this.media.startRecord();
console.log('started to record');
}
catch (e) {
this.showAlert('Could not start recording.');
}
}
stopRecording() {
try {
this.media.stopRecord();
console.log("media time",this.media.getDuration());
console.log('record stopped');
}
catch (e) {
this.showAlert('Could not stop recording.');
}
}
startPlayback() {
try {
this.media.play();
console.log('in start play back function');
console.log('in start play back function',this.media.play);
}
catch (e) {
this.showAlert('Could not play recording.');
}
}
stopPlayback() {console.log('playback stopped');
try {
this.media.stop();
}
catch (e) {
this.showAlert('Could not stop playing recording.');
}
}
showAlert(message) {
let alert = this.alertCtrl.create({
title: 'Error',
subTitle: message,
buttons: ['OK']
});
alert.present();
}
}
Currently i could able to make a folder into my mobile internal storage and i could able to see it using my file explorer and the recorded audio file is also visible in my internal storage, but i could not make a playback i get an error code 1 NOT_FOUND_ERR. And if i try to get duration i get -1 in my console And i am testing it in android device Thanks for your help in advance