Refered to this library https://github.com/iammert/RadioPlayerService I have this code for playing/pause radio
if (!mRadioManager.isPlaying())
mRadioManager.startRadio(RADIO_URL[0]);
else
mRadioManager.stopRadio();
and method for doing processes
@Override
public void onRadioStarted() {
runOnUiThread(new Runnable() {
@Override
public void run() {
//TODO Do UI works here.
mTextViewControl.setText("RADIO STATE : PLAYING...");
}
});
}
@Override
public void onRadioStopped() {
runOnUiThread(new Runnable() {
@Override
public void run() {
//TODO Do UI works here
mTextViewControl.setText("RADIO STATE : STOPPED.");
}
});
}
MyBroadcast Class
public class MyBroadcast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent intent1 = new Intent(context, MainActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
}
But in android 7 when i turn the screen off after 5-8 min radio stops playing music. I have done another example by doing in background and it is still the same thing. Please can anyone suggest me how to build a radio app without being affected by doze