Hello! I’m trying to create an Ionic 2 app that will record audio, after which the recorded audio can be played. After some searching, I found the MediaPlugin component, which API looked very promising.
My first attempt was to play some audio file from the internet, but I can’t get it to work. My page class looks like this:
Please can anyone provide code for android platform , I think path will be different. Also why did we create a member variable called filerecord couldnt we just call it directly after importing it
import { Component } from ‘@angular/core’;
import { AlertController } from ‘ionic-angular’;
import { Events } from ‘ionic-angular’;
import { LoadingController } from ‘ionic-angular’;
import { NavController } from ‘ionic-angular’;
import { MediaPlugin } from ‘ionic-native’;
import { Platform } from ‘ionic-angular’;
@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {
public media: MediaPlugin;
caminho: any;
constructor(
public alertCtrl: AlertController,
public events: Events,
public loadingCtrl: LoadingController,
public platform: Platform
) {}
startRecording(){
if (this.platform.is('ios')){
this.caminho = '../Library/NoCloud/recording.wav';
}else{
this.caminho = "recording.mp3";
}
//this program record only 3 seconds – to record more change loader time
let loader = this.loadingCtrl.create({
content:“Listening…”,
duration: 3000
});
try{
this.media = new MediaPlugin(this.caminho);
this.media.startRecord();
loader.present();
}catch (e){
this.finishedRecording("ERROR","Could not start recording.");
//throw e;
}
loader.onDidDismiss(()=>{
//loader.dismiss();
try{
this.media.stopRecord();
this.finishedRecording("Record finished","Sending audio to server!");
}catch (e){
this.finishedRecording("ERROR","Could not stop recording.");
}
});
}
play(){
try{
this.media.play();
}catch (e){
this.finishedRecording("ERROR","Could not play recording.");
}
i have this problem:
EXCEPTION: Error in ./Tabs class Tabs - inline template:0:43 caused by: No provider for
String!
Error: No provider for String! at NoProviderError.BaseError [as constructor]