2017-02-17 5 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) 
     } 

    } 

タイマーがスタートは、私が作成したメディアオブジェクトにその値を添付する必要がありますが、私はそれをしようとするとエラーがプロパティプッシュ

答えて

0

ないがmediapluginに存在しないことを撃ちますなぜこのプロパティを追加する必要があるのですが、これでエラーが修正されるはずです

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

+0

私はmedia:any = new MediaPlugin( "Vanan/audio.mp3")を設定すると、このリンクをたどってhttp://www.erikschierboom.com/2016/09/02/ionic2-audio-recorder/オーディオを録音します。 ); これは録音を停止できませんでした@Alex Ryltsov –

+0

なぜこのプロパティを追加する必要がありますか? –

+0

実際にメディアプラグインを使用していますが、私のコンソールでは-1を返しますので、手動でストップウォッチを開始してから、オーディオファイルにアタッチしてから再生してみてください。再生が可能なシンプルなオーディオレコーダーアプリ –

関連する問題