I have the following code in my controller ( this project is in ionic 1, and uses the cordova-plugin-media 5.0.3 plugin):
.controller('AudioCtrl', function($scope) {
console.log('in AudioCtrl');
let AudioFiles =[
{
url:"sample.aac"
},
{
url:"8b2d52b76e71729c8073b8340f7c0607.m4a"
},
{
url:"test1.mp4"
}
];
$scope.MediaFiles = [];
$scope.$on('$ionicView.beforeEnter',function(){
angular.forEach(AudioFiles,function(val,key){
console.log('adding',val);
let tempMediaObject = new Media(val['url'],function(){
//mediaSuccess
},function(){
//mediaError
},function(){
//mediaStatus
});
$scope.MediaFiles.push(tempMediaObject);
});
console.log($scope.MediaFiles);
});
$scope.play = function(index){
console.log('play this file', $scope.MediaFiles[index]);
$scope.MediaFiles[index].play();
};
$scope.pause = function(index){
$scope.MediaFiles[index].pause();
$scope.MediaFiles[index].release();
};
$scope.stop = function(index){
$scope.MediaFiles[index].stop();
$scope.MediaFiles[index].release();
};
})
and the following code in my page:
<div class="card">
<div style="white-space: normal;display: block;">File URL: {{audio.src}}</div>
<button class="button" ng-click="play($index)">Play</button>
<button class="button" ng-click="pause($index)">Pause</button>
<button class="button" ng-click="stop($index)">Stop</button>
</div>
</ion-item>
</ion-list>
The problem is that when I try playback, it always plays the audio file form the first Media object created(sample.aac). As you can see I have consoled logged the file that should be playing when I hit play and that is the correct file as selected, but what actually plays is always the first file. I have also tried this without the $scope.MediaFiles[index].release() call. This works fine on android but not on ios. I am testing on an iPhone X with ios 13.2.3. Anyone had this issue or know any solution ?