cordova-plugin-media
cordova-plugin-media copied to clipboard
getDuration returns a big number like 316000 and I can't kill the media file anywhere I still bloqued.
Hi everybody,
I'm working in Ionic 3 Project and All My current Project is based on this plugin, I get an issue when I try to get the duration for more then 30 local files in Android 5.01 and Android 5.1 ( I have tested only in those 2 devices )
So for test purpose I duplicate the same src local file in 30 tracks, and I try to get their duration all, sometimes it works fine but for more then 30 tracks the last tracks, getDuration() return a big number as 316520, and the Media File still bloqued at this situation:
I'm asking how to free or kill the Media file when it's bloqued in this situation Or is there a Direct Solution for this problem:
My Function Code:
getDurationAndSetToPlay(index,url){
this.myTracks[index] = this.media.create(url);
this.myTracks[index].play();
this.myTracks[index].setVolume(0.0);
let self = this;
this.tracks[index].get_duration_interval = setInterval(()=> {
self.tracks[index].duration = ~~(self.myTracks[index].getDuration());
if(self.tracks[index].duration > 0) {
self.stopPlayRecording(index);
self.myTracks[index].setVolume(1.0);
self.myTracks[index].stop();
self.setRecordingToPlay(index);
clearInterval(self.tracks[index].get_duration_interval);
}
}, 500);
}
I'm using a for loop to call this function to get all tracks duration simutaniously:
for (let index in urls){
this.getDurationAndSetToPlay(index,urls[index]);
My Local URL is like:
let urlLocal = this.file.externalRootDirectory+"MyProject/Folder1/Folder2/audioFile.mp3";
The Last Tracks after the 30 first Tracks are All bloqued at status code = 2 but doesn't play really and their duration still big number 316578 ..
Please Help Me I have to provide an App which supports 100 tracks (local files)
On android you have limited system resources, each time you call create it takes up resources. What you should try is track when you have already called create previously, if you have first call release and then create your new object. This releases the resources used by the previous object so they can be reused.
This may fix your problem as it sounds resource related as it only occurs when over a certain number of create calls have been made.