Move MediaPlayer to a Service. Troubleshoot issues surrounding loops when phone sleeping.
£10-20 GBP
Completed
Posted about 10 years ago
£10-20 GBP
Paid on delivery
I already have a fully functioning application that plays sounds when the user presses buttons on the MainActivity. There are around 15 sounds that loop continuously and 15 buttons.
I need to move the MediaPlayer from MainActivity into a Service and to only have ONE general MediaPlayer Service for every single sound that needs to be played. Currently the buttons on click associate a resId that the MediaPlayer uses to play the correct sound.
An example of this is:
public void onClick(View v) {
int resId;
switch ([login to view URL]()) {
case R.id.button_1:
resId = [login to view URL];
break;
case R.id.button_2:
resId = R.raw.brown_noise;
break;
default:
resId = [login to view URL];
break;
}
// Release any resources from previous MediaPlayer
if (mp != null) {
[login to view URL]();
}
// Create a new MediaPlayer to play this sound
mp = [login to view URL](this, resId);
[login to view URL](true);
[login to view URL]();
The MediaPlayer service needs to be able to listen for the resId and to play the correct sound accordingly. ONE MediaPlayer Service needs to be able to play ALL sounds and to play the correct sound depending on button press.
As well as this, the developer needs to rewrite sections of code such as:
PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if ([login to view URL]() && state == TelephonyManager.CALL_STATE_RINGING) {
[login to view URL](0,0);
} else if([login to view URL]() && state == TelephonyManager.CALL_STATE_IDLE) {
[login to view URL](1,1);
} else if([login to view URL]() && state == TelephonyManager.CALL_STATE_OFFHOOK) {
[login to view URL](0,0);
}
[login to view URL](state, incomingNumber);
}
};
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if(mgr != null) {
[login to view URL](phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
To work with the MediaPlayer Service as MainActivity will no longer be able to determine isPlaying() and will not be able to set the MediaPlayer volume as the MediaPlayer is outside of it, and is instead inside the Service.
This section will need writting also:
[login to view URL](new [login to view URL]() {
public void onClick(View v) {
if(null!=mp){
[login to view URL]();
[login to view URL](R.drawable.ic_action_volume_muted);
}
To ensure that the STOP button on the MainActivity will be able to tell the MediaPlayer Service to release() the MediaPlayer.
Additionally the developer will need to troubleshoot issues surrounding the MediaPlayer loops having a 0.5 second gap between them when the phone goes to sleep (Is locked or the screen dims). The sounds should loop continuously and seamlessly until the STOP button is called.
Hey
This one if fairly simple.
I have done the same thing in the past.
If you send me a document with all the requirements and accept my off then I'll get started right away.
I'm looking forward to workig on this project.
Kinds regards
Christophe