我遇到以下代码的问题.我在MediaController上调用了setPrevNextListener,并为Prev和Next定义了两个onClickListener.当我单击下一个按钮而不是前进一个轨道时,我前进两个轨道.这似乎是由于onCompletion被某种方式调用的事实. MediaPlayer.reset()是否会调用onCompletion?我已经包含了logcat输出和我的代码.如果我做错了,请告诉我.提前致谢.
logcat的:
02-24 00:36:34.826: D/MP(6675): Next Button Clicked,index was: 0
02-24 00:36:34.837: D/MP(6675): About to call Reset()
02-24 00:36:34.906: D/MP(6675): Inside setUpPlayer
02-24 00:36:34.917: D/MP(6675): Called setDataSource with index: 1
02-24 00:36:34.917: D/MP(6675): Leaving setUpPlayer
02-24 00:36:34.917: D/MP(6675): About to call prepareAsync()
02-24 00:36:34.937: D/MP(6675): Leaving next button
02-24 00:36:35.226: E/MediaPlayer(6675): Attempt to call getDuration without a valid mediaplayer
02-24 00:36:35.226: E/MediaPlayer(6675): error (-38,0)
02-24 00:36:35.276: E/MediaPlayer(6675): Error (-38,0)
02-24 00:36:35.287: D/MP(6675): Inside onCompletion
02-24 00:36:35.337: D/MP(6675): About to call Reset()
02-24 00:36:35.347: D/MP(6675): Inside setUpPlayer
02-24 00:36:35.356: D/MP(6675): Called setDataSource with index: 2
02-24 00:36:35.356: D/MP(6675): Leaving setUpPlayer
02-24 00:36:35.356: D/MP(6675): About to call prepareAsync()
02-24 00:36:35.377: D/MP(6675): Leaving onCompletion
02-24 00:36:36.517: D/MP(6675): Inside onPrepared,index is: 2
02-24 00:36:36.577: D/MP(6675): Leaving onPrepared
码:
public class MusicPlayerActivity extends Activity implements OnPreparedListener,OnCompletionListener,MediaController.MediaPlayerControl {
private MediaPlayer mp;
private MediaController mc;
private SonarDatabase db;
private SubsonicAPIConnector sonic;
ArrayList songs;
int index = 0;
private Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {