How to get an onCompletion handler from other clas

2019-08-15 02:44发布

问题:

Another silly question from this Android newbie, please be patient with me... :)

I've a class called Music that loads/plays music:

public class Music implements OnCompletionListener{
MediaPlayer mediaPlayer;
...
mediaPlayer.setOnCompletionListener(this);
...
public void onCompletion(MediaPlayer mediaPlayer) { ... }
...
}

Then, I have another class called MainClass, with the UI, that loads a Music with

Music track = Music(fileDescriptor);

Now, what I want is to do something in the UI (MainClass) when track ends playing or is stopped. But the MediaPlayer is inside Music, not inside MainClass, as well as setOnCompletionListener and the onCompletion method.

So, how MainClass knows that music has ended playing??

Thanks! L.