2017-02-17 86 views
1

我试图将新属性推送到创建的对象,但是当我这样做时,我收到错误,指出“MediaPlugin上不存在属性推送”。无法将新属性推送到媒体对象

import { File } from 'ionic-native' 
import { MediaPlugin } from 'ionic-native'; 


@Component({ 
    selector: 'page-home', 
    templateUrl: 'home.html' 
}) 
export class HomePage { 
    public total; 
    constructor(public navCtrl: NavController, 
       public alertCtrl: AlertController, 
) { 

       } 
media: MediaPlugin = new MediaPlugin("Vanan/audio.mp3"); 


    startRecording() {  
     try { 
      this.AudioFolderCreation(); 
      console.log("Audio folder created"); 
      this.starttime() 
      this.media.startRecord(); 
      this.status = false; 
      console.log("media recording" + JSON.stringify(this.media)); 


     } 
     catch (e) { 
      this.showAlert('Could not start recording.'); 
     } 
    } 


    stopRecording() { 
     try { 
      this.media.stopRecord(); 
      this.status = true; 
      this.reset()  
      console.log("Recording stopped Duration is:",this.media); 
      console.log("media recording" ,this.media + this.total); 
      var obj = this.total; 
      this.media.push(obj); 
      this.presentPrompt(); 
     } 
     catch (e) { 
      this.showAlert('Could not stop recording.'); 
     } 
    } 
/* Stopwatch */ 
    starttime(){ 
     console.log("timer started"); 
     if(this.running == 0){ 
      this.running = 1; 
      this.adder() 
     }else{ 
      this.running = 0; 
     } 
    } 

    reset(){ 
     console.log("timer reset"); 
     this.running = 0; 
     this.time = 0; 
     this.total = 0; 
     this.Sec = 0; 

    } 
    adder(){ 

     console.log("timer incrementor"); 
     if(this.running == 1){ 
      setTimeout(()=>{ 
       this.time++; 
       var mins = Math.floor(this.time/10/60); 
       var sec = Math.floor(this.time/10); 
       var tens = this.time/10; 

       this.total = mins + ':' + sec ; 
       this.Sec = sec;    
       this.adder() 

      },100) 
     } 

    } 

计时开始时的媒体开始和被停止了,我需要的是价值附加到创建的媒体对象,但是当我尝试它的错误拍摄了该属性推不mediaplugin

回答

0

不存在确定为什么你需要添加这个属性,但是这应该修复你的错误

media:any = new MediaPlugin(“Vanan/audio.mp3”);

+0

我跟着这个链接http://www.erikschierboom.com/2016/09/02/ionic2-audio-recorder/来记录音频,如果我设置媒体:any = new MediaPlugin(“Vanan/audio.mp3” ); 这个我无法阻止我的录音@Alex Ryltsov –

+0

为什么你需要添加这个属性? –

+0

实际上使用媒体插件,我应该得到媒体持续时间,但在我的控制台它返回-1,所以我手动开始秒表得到的时间,然后将其附加到音频文件,然后在播放我会得到它的时间,试图设计一个播放简单的录音机应用程序 –