I know this is strange, but this is my observation:
I managed to play some music with the Media Plugin in Ionic 1 using:
//Method 1: just plugin
mediaRes = new Media(myMusicPath, onMediaSuccess, onMediaError, onMediaStatus);
//Method 2: ngCordova
mediaRes = $cordovaMedia.newMedia(myMusicPath)
mediaRes.play().then(onMediaSuccess, onMediaError, onMediaStatus);
As read from other posts, the path is crucial:
"/android_asset/www/music/mymusic.mp3"
Basically the path name has been printed on my HTML so it won't be wrong.
For the first N times, it works properly. Then, on the (N + 1)th, it fails with error {"code":1}.
Why this happens? Do I need to somehow clear cache or something before re-initializing the variable? Currently I re-initialize the variable every time i run it.
EDIT:
Seems that it is OK to play infinitely if I just perform 'play()'
without re-initializing the same variable again. Would continue observing...
Apparently, the
release
function is required. And that solves the problem.