ngCordova Media plugin not working

I am building a simple media player using Ionic and the Soundcloud API. However, the media plugin doesn’t play anything and doesn’t even reach the .then part. This is my controller:

.controller('PlayerCtrl', function($scope, $cordovaMedia) {
$scope.cordovaPlay = function cordovaPlay(mediaUrl) {
	console.log("Play Button clicked");
	var src = mediaUrl + '?client_id=myclientid';
	console.log(src);
	var media = $cordovaMedia.newMedia(src).then(function() {
		// success
		console.log("Media successfully loaded");
	}, function() {
		// error
		console.log("Media load error");
	});
	
	media.play();
}
});

I just call the function on a button using ng-click, passing the stream URL:

<button class="button button-icon icon ion-play" ng-click="cordovaPlay('{{favorite.stream_url}}'); media.play();" ng-hide="isPlaying">
</button>

When I try the app on my device (I am aware that Cordova plugins won’t work in the browser) and click the play button, nothing happens. He doesn’t even log “Media successfully loaded” or “Media load error” in the console…

I also tried wrapping the function in $ionicPlatform.ready but that doesn’t change anything. The ngCordova filed gets called before cordova.js in my index file (I read somewhere that this is important).

Can anyone see where the problem is?

2 Likes

Bumpity bump!
Any help would be appreciated!

Anyone find solution ?

Anyone find solution ?

Hi,

Have you include this snippet in index.html

<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
<script src="cordova.js"></script>

and this in app.js

angular.module(‘starter’, [‘ionic’,‘ngCordova’])

manage in fontion of your code.