Getting error No provider for MediaPlugin

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

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

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

Anybody resolve this issue?

Did you read the previous comment?

1 Like


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

3 Likes