loops - How to remove the gap between lopping an audio file Android -
i'm trying play audio file x
number of times, , show value of x
user. problem can use mp.setlooping(true)
inorder loop audio without gaps between looping, cant handle number of repetitions it. used oncompletionlistener
fine, produces 1sec gap @ end or beginning of each repetition.
if use mp.setlooping(true)
no gap between looping.
if use oncompletionlistener
noticeable gap between looping.
the gap produced on android 4.x.x , 3.x.x . how can rid of gap ? in advance..
my code:
int n = 1; int maxcount = 15; //this value changes according user input. private void mpplay() { // todo auto-generated method stub mp.start(); mp.setoncompletionlistener(new oncompletionlistener() { @override public void oncompletion(mediaplayer mp) { if (n <= maxcount) { mp.start(); n++; tv.settext("counter:" + n); if (n >= maxcount) { n = 1; mp.stop(); } } } }); }
you try using 2 media players:
int n = 1; int maxcount = 15; //this value changes according user input. mediaplayer mp1 = new mediaplayer(); mp1.setoncompletionlistener(new oncompletionlistener() { @override public void oncompletion(mediaplayer mp) { if (n <= maxcount) { mp2.start(); mp1.setdatasource(<file>); mp1.prepare(); n++; tv.settext("counter:" + n); if (n >= maxcount) { n = 1; mp2.stop(); } } } }); mediaplayer mp2 = new mediaplayer(); mp2.setoncompletionlistener(new oncompletionlistener() { @override public void oncompletion(mediaplayer mp) { if (n <= maxcount) { mp1.start(); mp2.setdatasource(<file>); mp2.prepare(); n++; tv.settext("counter:" + n); if (n >= maxcount) { n = 1; mp1.stop(); } } } }); private void mpplay() { mp1.setdatasource(<file>); mp1.prepare(); mp1.start(); }
Comments
Post a Comment