So I have a collection of mp3 files in my raw folder. Each mp3 belongs to a category. From that category, the user can select one of eight mp3s to play.
For example: 1.mp3 2.mp3 3.mp3 4.mp3 5.mp3 6.mp3
mp3 (1-3) Belong to the category smooth jazz while, mp3(3-6) belong to alternative rock.
Reiterate the same method in each class, I'd rather have one method in the main activity, that I can call, from each class.
MediaPlayer mp3;
public void musicPlayer(//Here is where I want to have a variable x){
mp3 = MediaPlayer.create(this, R.raw.//Here is where variable x goes);
PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
mp3.pause();
} else if(state == TelephonyManager.CALL_STATE_IDLE) {
mp3.start();
} else if(state == TelephonyManager.CALL_STATE_OFFHOOK) {
mp3.pause();
}
super.onCallStateChanged(state, incomingNumber);
}
};
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if(mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
I want to instantiate variable x when I call the method musicPlayer, from a separate class.