Sunday, 11 August 2013

Unable to re setDatasource the second time when i try to play the next song

Unable to re setDatasource the second time when i try to play the next song

Hello my app generates a list of music player and it plays the music
player when user clicks on it,but when i swipe the screen to play the next
song,it just won't play the song...here is the code for it.the music
stops(because i have set it to stop first) but then nothing happens
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();
}
}
}

No comments:

Post a Comment