Cordova media plugin

Does it still work on latest ionic ? I’ve tried example from cordova and some examples from forum but nothing’s work. can some one show me a working example ?

got and error on console Error: Media is not defined

Can you share some code on what you’ve tried? It will help to troubleshoot.


I’ve used it with great success on my latest project using Ionic Beta 14.

As Nic mentioned - if you could share some code samples, it will help us to assist you.

I’ve followed the example from cordova.

angular.module('starter.controllers', ['ionic', 'ngCordova'])
.controller('DashCtrl', function($scope, $cordovaMedia) {
	$ = function() {
		var src = "sound/speech.mp3";
		var media = $cordovaMedia.newMedia(src).then(function() {;
		}, function () {
			// error

The audio is in the www/sound folder. This is what i actually want to play

Then i called the function from html page

<button class="button" ng-click="play()">Play</button>

I’ve included cordova.js on index.html

<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>

I’ve tried it on device and browser, here’s the error log

"Error: Media is not defined
" ionic.bundle.js:19387

above is my code, i’m using latest ionic version.

Well, at first glance, it all looks OK. Just a routine question, but have you actually installed the media plugin as well? i.e. by running:

ionic plugin add

on the command line? Sounds like the ‘Media’ class cannot be found?? Also try removing and re-adding your platform, i.e.

ionic platform remove ios
ionic platform add ios

to see if that makes a difference.

Yes i’ve installed the plugin using ionic and cordova. I’ve tried remove and re-add the platform but still same error. i even tried to make clean project and tried on both device and browser.

One more thing to try, and I think I had to do this on one of my projects…

Replace the line:

var media = $cordovaMedia.newMedia(src).then(function() {...


var media = new Media(src);
var mediaPromise = media.promise.then(function() {...

and see how that goes…

Still getting same error. I’m using html5 audio now, it works better, but only in browser tho

Yes, I ended up using HTML5 audio on one of my projects too. It works fine in iOS too. Android needs the Crosswalk browser extension though…

That leads me to believe that you are trying to test this from your web browser. You cannot test native device plugins such as Media, from your web browser.

You must use a device or simulator.


I’m using this plugin, but I get this error.

Error: [$injector:unpr] Unknown provider: $cordovaMediaProvider <- $cordovaMedia <- myCtrl

I add the plugin via CLI ionic

 ionic plugin add

This is my controller

.controller('myCtrl',function($scope,$stateParams,LuoghiService, $cordovaMedia) {
        $ = function () {
            var src = "audio/music.mp3";
            var media = $cordovaMedia.newMedia(src).then(function() {
            }, function () {
                // error

Can someone help me?

this plugin only works if you try it on device

1 Like

I’m facing the same issue.
Error: [$injector:unpr] Unknown provider: $cordovaMediaProvider <- $cordovaMedia
Does someone has a solution?

Check the version of ng-cordova that you are using. It looks like as of 0.1.18-alpha that they started using “$cordovaMedia2” instead of $cordovaMedia. I was hitting the same problem and switching to $cordovaMedia2 fixed it.


Thanks! this worked for me :smile:

Was this emulated in the browser or the ionic Lab?

Hi nicraboy,

I am following your tutorial to play a record in my list but I am getting the same error here.

122020   error    ReferenceError: Media is not defined
at new i (