javascriptangularjscordovaionic-frameworkcordova-media-plugin

Undefined object in Java Script Ionic framework


I wrote a service for playing Media on iOS and Android in Ionic framework. It use Media plugin of Cordova. I am init media object and play it with this code in Java Script,but it returns undefined object error.

var self  = {
'currentTrack': null,
'initPlayer': function (videoID) {
self.currentTrack = Media(IP_ADDRESS + 'stream/'+videoID);
//self.currentTrack = _track;
console.log('initd');
},
'Play': function () {
console.log(self.currentTrack);

    self.currentTrack.play();



}
};

And in the template I init the audioPlayer in this way:

<ion-content ng-init="audioPlayer.initPlayer('foo')>

and in a button I declare the playing function:

<button ng-click="audioPlayer.Play()"

Error:

Error: undefined is not an object (evaluating 'self.currentTrack.play')

Solution

  • I didn't declare my function in deviceready event correctly. It works now.