离子 2.1.14 MediaPlugin 方法未定义

ionic 2.1.14 MediaPlugin methods undefined

我似乎无法将方法放在具有 MediaPlugin 导入的 属性 上。 它告诉我它是 undefined。 我想将文件 link 保留在 class 中并从我的 home.html.

执行 wavplay()

这是我的代码:

//ionic start blank --v2    
//home.ts

    import { Component } from '@angular/core';
    import { NavController } from 'ionic-angular';
    import { MediaPlugin } from 'ionic-native';

    @Component({
      selector: 'page-home',
      templateUrl: 'home.html'
    })

    export class HomePage {

      constructor(public navCtrl: NavController) {}

      wavfile = new MediaPlugin('file:///android_asset/www/mp3/testwav.wav');

      wavplay() {
        this.wavfile.play(); // .play() undefined
      }
      mp3play() {
        new MediaPlugin('file:///android_asset/www/mp3/testmp3.mp3').play(); //But this works
      }
    }

有什么解决办法吗?我正在 android 6.0.1

上测试我的应用

如果要将文件名保留在 class 中,请使用这样的 属性

//ionic start blank --v2    
//home.ts

    import { Component } from '@angular/core';
    import { NavController } from 'ionic-angular';
    import { MediaPlugin } from 'ionic-native';

    @Component({
      selector: 'page-home',
      templateUrl: 'home.html'
    })

    export class HomePage {

      private wavfile: any;  // <- Declare the class property

      constructor(public navCtrl: NavController) {
        // Initialize the property
        this.wavfile = new MediaPlugin('file:///android_asset/www/mp3/testwav.wav');
      }

      public wavplay(): void {
        this.wavfile.play();  // <- use it
      }
    }