我实现了简单的媒体播放器,但我想通过使用处理程序来处理我的播放器。例如 - 我的 OnClick:
public void playerControls(View v) {
switch (v.getId()) {
case R.id.Play:
if (!PlayerService.isPlay()) {
Log.i(TAG, DeviceHelper.getMethodName() + " Media start play");
play.setImageResource(R.drawable.pause);
service.play();
trackTitle.setText(service.getTrackTitle());
} else {
Log.i(TAG, DeviceHelper.getMethodName() + " Media pause");
play.setImageResource(R.drawable.play);
service.pause();
trackTitle.setText("Paused...");
}
break;
case R.id.NextTrack:
Log.i(TAG, DeviceHelper.getMethodName() + " Next track please");
if (PlayerService.isPlay()) {
service.nextTrack();
trackTitle.setText(service.getTrackTitle());
}
break;
case R.id.PreviousTrack:
Log.i(TAG, DeviceHelper.getMethodName() + " Previous track please");
if (PlayerService.isPlay()) {
service.previousTrack();
trackTitle.setText(service.getTrackTitle());
}
break;
}
}
我想通过处理程序发送消息,如下所示:
case R.id.NextTrack:
Log.i(TAG, DeviceHelper.getMethodName() + " Next track please");
if (PlayerService.isPlay()) {
Message m = new Message;
m.what = MyConstant;
handler.sendMessage(m);
trackTitle.setText(service.getTrackTitle());
}
break;
并在另一个类中处理此消息,我在其中实现我的逻辑。但在这个实现中,我没有看到我的消息。
你能提供一些帮助吗?谢谢