Play mp3 audio files with cordova media plugin

January 7, 2016

Publicidad / Advertisement

Trying to play Audio files in ionic project but it seems the Cordova plugin media is not working.

Plugin installed:   cordova-plugin-media 1.0.1 “Media”

and version of ng-cordova that i am using: v0.1.20-alpha

Code in controller.js

.controller('ListCtrl', function($scope, $ionicModal, $cordovaSQLite, $cordovaMedia, $ionicPlatform) {
  var media;
  $ionicPlatform.ready(function() {

    $scope.playAudio = function(url_audio) {
      // create media promise
      media = $cordovaMedia.newMedia(url_audio);


just in case, i am using $ionicPlatform.ready(function() { , but i am not sure if is that necessary.

Here is the template list.html with one button that calls the playAudio function:

When i test this code in web browser, i get this error:

ReferenceError: Media is not defined
    at new i (ng-cordova.min.js:8)
    at Object.newMedia (ng-cordova.min.js:8)
    at Scope.$scope.playAudio (controllers.js:136)
    at $parseFunctionCall (ionic.bundle.js:21044)
    at ionic.bundle.js:53458
    at Scope.$eval (ionic.bundle.js:23100)
    at Scope.$apply (ionic.bundle.js:23199)
    at HTMLButtonElement. (ionic.bundle.js:53457)
    at HTMLButtonElement.eventHandler (ionic.bundle.js:11713)

Any solution or explanation?

Publicidad / Advertisement


Topics: ionic framework | No Comments »


About Me

Put something about you here by editing the right sidebar.