OK I got it to work. This will save the file as a ringtone, notification, or alarm based on the context menu. (Only ringtone function is shown due to space conservation)
Need help with:
For some reason no sound plays after awhile.(about 20 or so presses and won't play again until you back out of the app and launch it again) Also I've been told "/sdcard/media/etc" isn't "the correct way" to do it.
If anyone has any suggestions on how to
1.release/pause/stop the sound from playing when the home button is pressed, a text is recieved, or the back button is pressed to exit the app, etc
and
2.the correct way to get the sdcard. I'd appreciate it.
MediaPlayer mp1;
MediaPlayer mp2;
MediaPlayer mp3;
MediaPlayer mp4;
MediaPlayer mp5;
protected void onDestroy() {
super.onDestroy();
if(mp1 != null){
mp1.release();
}
if(mp2 != null){
mp2.release();
}
if(mp3 != null){
mp3.release();
}
if(mp4 != null){
mp4.release();
}
if(mp5 != null){
mp5.release();
}
}
protected void onPause() {
super.onPause();
if(mp1 != null){
mp1.stop();
}
if(mp2 != null){
mp2.stop();
}
if(mp3 != null){
mp3.stop();
}
if(mp4 != null){
mp4.stop();
}
if(mp5 != null){
mp5.stop();
}
}
}
protected void onResume() {
super.onResume();
}
Answer to Q1: Add a onPause
method to your activity and call MediaPlayer's stop()
method. You should also add a onDestroy
method and call release
to free the resources used by the mediaplayer.
Answer to Q2: Take a look at this post. For more details read the Android Developers info on Data Storage