Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onCompletion isn't being called when I would expect it to

Tags:

android

I have a MediaPlayer member variable posted in my parent class, and after I start it, it doesn't ever call onCompletion, or at least onCompletionListener doesn't ever catch it? My code looks something to this effect

mediaPlayer = Mediaplayer.create(this, currentSample);
mediaPlayer.start();

elsewhere in code is my onCompletionListener

mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
    public void onCompletion(MediaPlayer mp) {      
        if (repeatFlag == true) {
            handler.removeCallbacks(sampleRunnable);
            handler.postDelayed(sampleRunnable, delay);
        }
    }   
});

I'm using the handler to call sampleRunnable because I want to loop it at a specified delay interval. However, onCompletion seems to never be called. I'm quite positive of this because I've set breakpoints in onCompletion which never suspends the program, and I've tried stepping through and it never seems to be called. Any ideas?

like image 761
HD_Mouse Avatar asked Dec 29 '22 02:12

HD_Mouse


2 Answers

    mediaPlayer.start();
    mediaPlayer.setOnCompletionListener(new OnCompletionListener() 
    {
        @Override
        public void onCompletion(MediaPlayer arg0) 
        {
            Log.v("Tag", "Completed");
        }
    });

This snippet works fine. The only difference is the "@Override" and I'm not sure if the "@Override" has effect on the code.

like image 66
iamtheexp01 Avatar answered Jan 31 '23 07:01

iamtheexp01


On my experience, the listener is not triggered on some devices :/

like image 27
AlvaroSantisteban Avatar answered Jan 31 '23 07:01

AlvaroSantisteban