2017-02-17 37 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,所以我手動開始秒錶得到的時間,然後將其附加到音頻文件,然後在播放我會得到它的時間,試圖設計一個播放簡單的錄音機應用程序 –