How to get an onCompletion handler from other class?

这一生的挚爱 提交于 2019-12-24 07:38:31

问题


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.

来源:https://stackoverflow.com/questions/13059997/how-to-get-an-oncompletion-handler-from-other-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!