For my Ionic framework iOS and Android Media service, I used the Cordova Media plugin. When initializing and playing a media object in JavaScript, I encountered an undefined object error.
var self = {
'currentTrack': null,
'initPlayer': function (videoID) {
self.currentTrack = Media(IP_ADDRESS + 'stream/'+videoID);
console.log('initd');
},
'Play': function () {
console.log(self.currentTrack);
self.currentTrack.play();
}
};
In the template, I initialized the audio player like this:
<ion-content ng-init="audioPlayer.initPlayer('foo')>
And declared the play function for a button:
<button ng-click="audioPlayer.Play()"
The error message received was:
Error: undefined is not an object (evaluating 'self.currentTrack.play')