Media is not defined in ionic service?


#1

Hello, I would like to run a service to access my media from differents controllers.

Here is my code for services.js:

angular.module('starter.services', [])

.service('player', function ($ionicPlatform, $cordovaMedia, $timeout, $window) {
$ionicPlatform.ready(function() {
        var playlist = [];
	console.log($cordovaMedia);
	$timeout(function(){
		var player = new Media(null, null, null, null);
	}, 2000);

	return {
			add: function (audio, play) {
					playlist.push(audio);
					
			},
			setProperty: function(value) {
					property = value;
			}
	};
});
})

I got the error:

ReferenceError: Media is not defined
at services.js:7

I don’t understand why is this happening, as using the same code in a controller instead of a service would work well.

PS: Yes I have installed cordova media plugin.

Thank you


#2

I want to kill myself. I am looking to fix this for around 3 hours, when I realized I was running the code in browser.

That hurts!