Getting error No provider for MediaPlugin


#1

here’s my code

import {Page, NavController, NavParams} from 'ionic-angular';
import {TesouroDataService} from '../../providers/tesouro-data-service/tesouro-data-service';
import {Post} from '../../providers/tesouro-data-service/tesouro-data-service';
import {MediaPlugin} from 'ionic-native';


@Page({
  templateUrl: 'build/pages/item-detail/item-detail.html',
})
export class ItemDetailPage {

  post: any;
  playing = false;

  hasAudio = false;

  constructor(private nav: NavController, navParams: NavParams, private mp:MediaPlugin) {
    this.post = navParams.get('item');
    if (this.post.audio != '') {
      this.hasAudio = true;
    } else {
    this.hasAudio = false;
    }
  }

play(){
  this.mp.play(this.post.audio);
  this.playing = true;
 
}

stop(){
  this.mp.stop();
  this.playing = false;
   this.mp.release();
  }
}

thank’s


#2

I have the exact same issue, did you solve it?


#3

Angular has changed quite a bit since this topic was originally posted, so can you share some code?


#4

Anybody resolve this issue?


#5

Did you read the previous comment?


#6


That is the documentation for Media Plugin.

Usually you add ionic native plugins like that:
add the plugin to your app with cli command
ionic plugin add --save PLUGINNAME

install the ionic native plugin from npm
npm install --save @ionic-native/PLUGINNAME

import it in your page/provider and in your app.module.ts
import { PLUGINNAME } from '@ionic-native/PLUGINNAME';

add it to your app.module.ts
providers: [ PLUGINNAME ]

use DI in your constructor in your page/provider
constructor(private pluginName: PLUGINNAME) { }

then you can use it in your code