I'm trying to make a sort of soundboard app in Android Studio. For now I have three buttons: 2 of them play specific audio files and the other one stops the audio. Everything works except if you play one audio file while another one is going already they both play at the same time and the stop button no longer works on either of them. You have to exit the app. I cannot figure out how to get the first file to quit before playing the second. Here is my code so far:
package com.something.example.com;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
private Button startLie, startTruth,
stopScan;
private MediaPlayer play;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startLie = (Button) findViewById(R.id.startlie);
startLie.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
play = MediaPlayer.create(MainActivity.this, R.raw.lie_detector);
play.start();
play.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer play) {
play.release();
}
});
}
});
stopScan = (Button) findViewById(R.id.stopScan);
stopScan.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
play.stop();
};
});
startTruth = (Button) findViewById(R.id.starttruth);
startTruth.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
play = MediaPlayer.create(MainActivity.this, R.raw.truth_detector);
play.start();
play.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer play) {
play.release();
}
});
}
});
So I seem to have been able to finally get this to work. I basically created a stopPlaying function (placed at the end of my file. and then called it every time before the audio files play. Here's the code again, and this time with a couple more buttons.
package com.something.example;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
private Button startLie, startTruth,
startIdiot, startGenius, stopScan;
private MediaPlayer play;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startLie = (Button) findViewById(R.id.startlie);
startLie.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
stopPlaying();
play = MediaPlayer.create(MainActivity.this, R.raw.lie_detector);
play.start();
play.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer play) {
play.release();
}
});
}
});
stopScan = (Button) findViewById(R.id.stopScan);
stopScan.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
play.stop();
};
});
startTruth = (Button) findViewById(R.id.starttruth);
startTruth.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
stopPlaying();
play = MediaPlayer.create(MainActivity.this, R.raw.truth_detector);
play.start();
play.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer play) {
play.release();
}
});
}
});
startIdiot = (Button) findViewById(R.id.startidiot);
startIdiot.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
stopPlaying();
play = MediaPlayer.create(MainActivity.this, R.raw.idiot_detector);
play.start();
play.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer play) {
play.release();
}
});
}
});
startGenius = (Button) findViewById(R.id.startgenius);
startGenius.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
stopPlaying();
play = MediaPlayer.create(MainActivity.this, R.raw.genius_detector);
play.start();
play.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer play) {
play.release();
}
});
}
});
}
private void stopPlaying() {
if (play != null) {
play.stop();
play.release();
play = null;
}
}
Related
image shows a screenshot of the app interfaceI am very new to writing any kind of code, and am attempting to build an app that can host two podcasts. I want users to be able to play two separate podcasts on the app, and so need to use two separate onStop methods. However, I get the error:
onStop()' is already defined in "app name"
Is there a way to implement 2 separate onStop methods?
package com.example.breastiesapp;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
public class MindActivity extends AppCompatActivity {
public Button button;
MediaPlayer mediaPlayer;
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mind);
mediaPlayer = null;
//Body Button
button = (Button) findViewById(R.id.bodyBTN);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MindActivity.this,BodyActivity.class);
startActivity(intent);
}
});
//Home Button
button = (Button) findViewById(R.id.homeBTN);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MindActivity.this, MainActivity.class);
startActivity(intent);
}
});
}
//Play Pod 1
public void PlayPod1(View view) {
switch (view.getId()) {
case R.id.btnPlayPod1:
if (mediaPlayer == null) {
mediaPlayer = MediaPlayer.create(this, R.raw.pod1feelmorejoy);
}
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mediaPlayer) {
stopPod1();
}
});
mediaPlayer.start();
break;
case R.id.btnPausePod1:
if (mediaPlayer !=null)
mediaPlayer.pause();
break;
case R.id.btnStopPod1:
if (mediaPlayer != null) {
mediaPlayer.stop();
stopPod1();
}
break;
}
}
private void stopPod1() {
mediaPlayer.release();
mediaPlayer = null;
}
#Override
protected void onStop() {
super.onStop();
stopPod1();
}
//Play Pod 2
public void PlayPod2(View view) {
switch (view.getId()) {
case R.id.btnPlayPod2:
if (mediaPlayer == null) {
mediaPlayer = MediaPlayer.create(this, R.raw.usingmindfulnesstoreducestressandstrengthenyourimmune);
}
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mediaPlayer) {
stopPod2();
}
});
mediaPlayer.start();
break;
case R.id.btnPausePod2:
if (mediaPlayer !=null)
mediaPlayer.pause();
break;
case R.id.btnStopPod2:
if (mediaPlayer != null) {
mediaPlayer.stop();
stopPod2();
}
break;
}
}
private void stopPod2() {
mediaPlayer.release();
mediaPlayer = null;
}
#Override
protected void onStop() {
super.onStop();
stopPod1();
}
}
I have a few buttons that play sounds through the mediaplayer everytime you tap them.
If you tap them too often though, they go silent. All of them, no matter what button you hit and it doesn't matter how much time you leave between taps.
Afterwards I have to completely kill the app in order to get sound again.
import androidx.appcompat.app.AppCompatActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button bt_kick, bt_closed_hat, bt_clap, bt_snare, bt_subdrop, bt_open_hat, bt_shaker_high, bt_shaker_low;
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt_kick = (Button) findViewById(R.id.kick);
bt_closed_hat = (Button) findViewById(R.id.closed_hat);
bt_clap = (Button) findViewById(R.id.clap);
bt_snare = (Button) findViewById(R.id.snare);
bt_subdrop = (Button) findViewById(R.id.subdrop);
bt_open_hat = (Button) findViewById(R.id.open_hat);
bt_shaker_high = (Button) findViewById(R.id.shaker_high);
bt_shaker_low = (Button) findViewById(R.id.shaker_low);
bt_kick.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.kick);
mp.start();
}
});
bt_closed_hat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.closed_hat);
mp.start();
}
});
bt_clap.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.clap);
mp.start();
}
});
bt_snare.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.snare);
mp.start();
}
});
bt_subdrop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.subdrop);
mp.start();
}
});
bt_open_hat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.open_hat);
mp.start();
}
});
bt_shaker_high.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.shaker_high);
mp.start();
}
});
bt_shaker_low.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.shaker_low);
mp.start();
}
});
}
}
I am making an app which if you click on a button an audio will play but the audio is not playing in last two buttons and can you also please tell me how can I stop the audio if I click on the audio button again ?? Here's The Full Code. Thanks in Advance. It's in gdsph_btn & aspamm_btn
package com.agrimplayz.radhasoamipaath;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button rrjk_btn, gdsph_btn, aspamm, stop_btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rrjk_btn = findViewById(R.id.rrjk_btn);
final MediaPlayer mediaPlayer = MediaPlayer.create(this,R.raw.radhasoami_rakshak_jeev_ke);
rrjk_btn.setOnClickListener(new View.OnClickListener() {
int counter = 0;
#Override
public void onClick(View v) {
if(counter == 2)
mediaPlayer.pause();
mediaPlayer.start();
gdsph_btn = findViewById(R.id.gdsph_btn);
MediaPlayer mediaPlayer = MediaPlayer.create(MainActivity.this,
R.raw.guru_dhara_sheesh_par_haath);
final MediaPlayer finalMediaPlayer1 = mediaPlayer;
gdsph_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finalMediaPlayer1.start();
}
});
aspamm = findViewById(R.id.gdsph_btn);
mediaPlayer = MediaPlayer.create(MainActivity.this,
R.raw.ae_satguru_pita_aur_malik_mere);
final MediaPlayer finalMediaPlayer = mediaPlayer;
aspamm.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finalMediaPlayer.start();
}
});
}
});
}
}
you can try this code:
public class MainActivity extends AppCompatActivity {
private Button rrjk_btn, gdsph_btn, aspamm, stop_btn;
int counter = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MediaPlayer mediaPlayer1 = MediaPlayer.create(this, R.raw.radhasoami_rakshak_jeev_ke);
rrjk_btn = findViewById(R.id.rrjk_btn);
rrjk_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (counter == 2)
{
mediaPlayer1.pause();
}
mediaPlayer1.start();
counter++;
}
});
//
MediaPlayer mediaPlayer2 = MediaPlayer.create(MainActivity.this, R.raw.guru_dhara_sheesh_par_haath);
gdsph_btn = findViewById(R.id.gdsph_btn);
gdsph_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mediaPlayer2.start();
}
});
//
aspamm = findViewById(R.id.gdsph_btn);
MediaPlayer mediaPlayer3 = MediaPlayer.create(MainActivity.this, R.raw.ae_satguru_pita_aur_malik_mere);
aspamm.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mediaPlayer3.start();
}
});
}
}
I have an activity named Player Activity in which I am streaming music with the help of MediaPlayer API. Whenever my activity is created a notification is displayed which has some basic control of the music player.
So when I tap on my notification it jumps back to the Player Activity, but the state of the activity is lost.
Before tapping on notification :
After tapping on notification :
Here is the code of my notification's Pending Intent
Intent notifyIntent = new Intent(context, PlayerActivity.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
notifyIntent.setAction("android.intent.action.MAIN");
notifyIntent.addCategory("android.intent.category.LAUNCHER");
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Here is the code for PlayerActivity.java :
package com.example.user.musicplayer;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaMetadataRetriever;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import com.squareup.picasso.Picasso;
import java.util.concurrent.TimeUnit;
import de.hdodenhof.circleimageview.CircleImageView;
public class PlayerActivity extends AppCompatActivity implements MediaPlayer.OnBufferingUpdateListener,MediaPlayer.OnCompletionListener{
private static Button btn_play_pause;
private Button btnToggleRepeat;
private Button btnStop;
private SeekBar seekBar;
private TextView textView;
public static MediaPlayer mediaPlayer;
private int mediaFileLength;
private int realtimeLength;
private String musicUrl;
private String imageUrl;
final Handler handler = new Handler();
private boolean isRepeat;
private CircleImageView musicImage;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
Log.d("TAG", "onCreate");
NotificationGenerator.customBigNotification(getApplicationContext());
musicUrl = getIntent().getStringExtra("musicUrl");
imageUrl = getIntent().getStringExtra("imageUrl");
seekBar = (SeekBar)findViewById(R.id.seekbar);
seekBar.setMax(99); // 100% (0~99)
seekBar.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if(mediaPlayer.isPlaying())
{
SeekBar seekBar = (SeekBar)v;
int playPosition = (mediaFileLength/100)*seekBar.getProgress();
mediaPlayer.seekTo(playPosition);
}
return false;
}
});
textView = (TextView)findViewById(R.id.txtTime);
btnToggleRepeat = findViewById(R.id.btnRepeat);
btnStop = findViewById(R.id.btnStop);
musicImage = findViewById(R.id.musicImgView);
Picasso.get().load(imageUrl).placeholder(R.drawable.music).error(R.drawable.music).into(musicImage);
btn_play_pause = (Button) findViewById(R.id.btnTogglePlay);
btn_play_pause.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final ProgressDialog mDialog = new ProgressDialog(PlayerActivity.this);
AsyncTask<String,String,String> mp3Play = new AsyncTask<String, String, String>() {
#Override
protected void onPreExecute() {
mDialog.setMessage("Please wait");
mDialog.show();
}
#Override
protected String doInBackground(String... params) {
try{
mediaPlayer.setDataSource(params[0]);
mediaPlayer.prepare();
}
catch (Exception ex)
{
}
return "";
}
#Override
protected void onPostExecute(String s) {
mediaFileLength = mediaPlayer.getDuration();
realtimeLength = mediaFileLength;
if(!mediaPlayer.isPlaying())
{
playMusic();
}
else
{
pauseMusic();
}
updateSeekBar();
mDialog.dismiss();
}
};
mp3Play.execute(musicUrl); // direct link mp3 file
}
});
btnToggleRepeat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(isRepeat){
isRepeat = false;
mediaPlayer.setLooping(false);
btnToggleRepeat.setText("Repeat");
}
else{
isRepeat = true;
mediaPlayer.setLooping(true);
btnToggleRepeat.setText("Single");
}
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
mediaPlayer.pause();
mediaPlayer.stop();
}
catch (Exception e){
Toast.makeText(PlayerActivity.this, "Opps! sorry something bad happened", Toast.LENGTH_SHORT).show();
}
}
});
mediaPlayer = new MediaPlayer();
mediaPlayer.setOnBufferingUpdateListener(this);
mediaPlayer.setOnCompletionListener(this);
}
public void pauseMusic() {
mediaPlayer.pause();
btn_play_pause.setText("Play");
}
public void playMusic() {
mediaPlayer.start();
btn_play_pause.setText("Pause");
}
private void updateSeekBar() {
seekBar.setProgress((int)(((float)mediaPlayer.getCurrentPosition() / mediaFileLength)*100));
if(mediaPlayer.isPlaying())
{
Runnable updater = new Runnable() {
#Override
public void run() {
updateSeekBar();
realtimeLength-=1000; // declare 1 second
textView.setText(String.format("%d:%d",TimeUnit.MILLISECONDS.toMinutes(realtimeLength),
TimeUnit.MILLISECONDS.toSeconds(realtimeLength) -
TimeUnit.MILLISECONDS.toSeconds(TimeUnit.MILLISECONDS.toMinutes(realtimeLength))));
}
};
handler.postDelayed(updater,1000); // 1 second
}
}
#Override
protected void onResume() {
super.onResume();
Log.d("TAG", "onResume");
}
#Override
protected void onStart() {
super.onStart();
Log.d("TAG", "onStart");
}
#Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
seekBar.setSecondaryProgress(percent);
}
#Override
public void onCompletion(MediaPlayer mp) {
if(!mediaPlayer.isLooping())
btn_play_pause.setText("Play");
}
#Override
protected void onStop() {
super.onStop();
}
#Override
protected void onPause() {
super.onPause();
}
public static class DownloadCancelReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("notificationPlayer","Received Cancelled Event");
}
}
}
Thanks in advance. Pardon me if the explanation is not clear, because if i might have right words to explain it, I would have googled it.
Add this to your PlayerActivity activity in manifest :
android:launchMode="singleTask"
And use these flags in the intent for pendingintent :
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
**Down here I am trying to build a music app in android studio,my app is working fine displaying all my SD card songs and play too ,all button works but when I click on next button it works normally but don't know why app sometimes gets stopped working and shows runtime exception ->>please open the image of run log of the application.
package com.example.ramandeepsingh.tunes;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.Toast;
import java.io.File;
import java.util.ArrayList;
import java.util.jar.Manifest;
public class PlayerActivity extends AppCompatActivity{
static MediaPlayer mp;//assigning memory loc once or else multiple songs will play at once
int position;
SeekBar sb;
ArrayList<File> mySongs;
Thread updateSeekBar;
Button pause,forward,reverse,next,previous;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
pause = (Button)findViewById(R.id.pause);
forward = (Button)findViewById(R.id.forward);
previous = (Button)findViewById(R.id.previous);
next = (Button)findViewById(R.id.next);
reverse = (Button)findViewById(R.id.reverse);
sb=(SeekBar)findViewById(R.id.seekBar);
updateSeekBar=new Thread(){
#Override
public void run(){
int totalDuration = mp.getDuration();
int currentPosition = 0;
// sb.setMax(totalDuration);
while(currentPosition < totalDuration){
try{
sleep(500);
currentPosition=mp.getCurrentPosition();
}
catch (InterruptedException e){
e.printStackTrace();
System.out.println(e);
}
sb.setProgress(currentPosition);
}
}
};
if(mp != null){
mp.stop();
mp.release();
}
Intent i = getIntent();
Bundle b = i.getExtras();
mySongs = (ArrayList) b.getParcelableArrayList("songs");
position = b.getInt("pos",0);
Uri u = Uri.parse(mySongs.get(position).toString());
mp = MediaPlayer.create(getApplicationContext(),u);
mp.start();
sb.setMax(mp.getDuration());
updateSeekBar.start();
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
mp.seekTo(seekBar.getProgress());
}
});
pause.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sb.setMax(mp.getDuration());
if(mp.isPlaying()){
pause.setText(">");
mp.pause();
}
else {
pause.setText("||");
mp.start();
}
}
});
forward.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sb.setMax(mp.getDuration());
mp.seekTo(mp.getCurrentPosition()+5000);
}
});
reverse.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sb.setMax(mp.getDuration());
mp.seekTo(mp.getCurrentPosition()-5000);
}
});
next.setOnClickListener(new
View.OnClickListener() {
#Override
public void onClick(View v) {
mp.stop();
mp.reset();
position=((position+1)%mySongs.size());
Uri u = Uri.parse(mySongs.get( position).toString());
mp = MediaPlayer.create(getApplicationContext(),u);
mp.start();
sb.setMax(mp.getDuration());
updateSeekBar.start();
}
});
previous.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mp.stop();
mp.release();
position=((position-1)<0)?(mySongs.size()-1):(position-1);
Uri u = Uri.parse(mySongs.get( position).toString());//%mysongs so that it do not go to invalid position
mp = MediaPlayer.create(getApplicationContext(),u);
mp.start();
}
});
}}