你好,我的应用程序会生成一个音乐播放器列表,当用户点击它时它会播放音乐播放器,但是当我滑动屏幕播放下一首歌曲时,它就不会播放这首歌......这是它的代码.音乐停止(因为我已将其设置为先停止),但随后什么也没有发生
public class NowPlaying extends Activity implements Serializable {
MediaPlayer mp =new MediaPlayer();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.now_playing);
Intent i = getIntent();
final int position=i.getIntExtra("Data2", 0);
final ArrayList<SongDetails> songs = getIntent().getParcelableArrayListExtra("Data1");
SongDetails songDetails = songs.get(position) ;
Button bfake=(Button) findViewById(R.id.bFake);
LinearLayout LL=(LinearLayout) findViewById(R.id.LL);
Button Pause=(Button)findViewById(R.id.bPlayPause);
Playservice(songs,position,0 );
bfake.setOnTouchListener(new OnSwipeTouchListener()
{
public void onSwipeTop() {
mp.stop();
mp.release();
}
public void onSwipeRight() {
//mp.stop();
//mp.release();
Playservice(songs,position,-1 );
}
public void onSwipeLeft() {
//mp.stop();
//mp.release();
Playservice(songs,position,1 );
}
public void onSwipeBottom() {
mp.stop();
mp.release();
}
});
LL.setOnTouchListener(new OnSwipeTouchListener() {
public void onSwipeTop() {
mp.stop();
mp.release();
}
public void onSwipeRight() {
//mp.stop();
//mp.release();
Playservice(songs,position,-1 );
}
public void onSwipeLeft() {
//mp.stop();
//mp.release();
Playservice(songs,position,1 );
}
public void onSwipeBottom() {
mp.stop();
mp.release();
}
});
Pause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
mp.stop();
mp.release();
}
});
}
private void Playservice( ArrayList<SongDetails> songs, int position, int i ) {
try {
String ab=songs.get(position+i).getPath2().toString();
if(mp.isPlaying())
{ mp.stop();
mp.release();
}
mp.reset();
mp.setDataSource(ab) ;
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}