MediaPlayer
传递给此方法的属性与MediaPlayer
刚刚完成的相同,因此只要您保留指向每个媒体播放器的指针(例如通过全局变量),那么您需要做的就是检查您收到的媒体播放器:
public class MyClass implements OnClompleteListener
{
MediaPlayer player1, player2, player3;
//initialize them
player1.setOnCompleteListener(this);
player2.setOnCompleteListener(this);
player3.setOnCompleteListener(this);
@Override
public void onCompletion(MediaPlayer mp)
{
if (mp == player1)
{
//TODO handle player 1 completion
}
else if (mp == player2)
{
//TODO handle player 2 completion
}
else if (mp == player3)
{
//TODO handle player 3 completion
}
}
}
您也可以在线处理此问题,而无需实现OnCompleteListener
:
player1.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onCompletion(MediaPlayer mp)
{
//mp IS ALWAYS EQUAL TO player1!
}
});