android – How to keep audio in the background to use other applications

Hello, I have an app to stream audio, it works very well when the app is in the foreground, when I leave the app the audio stops and I want to make it stay while using other apps, that means that the audio stays on. background since it is an online station or (Radio Online) and I want users to be able to use other apps while listening, here I leave the code I have for them to review it and they can tell me it is missing or if there is any error.
Can someone help me solve this problem please.

MainActivity code:

public class MainActivity extends AppCompatActivity {

Button play;
AVLoadingIndicatorView progressbar;
MediaPlayer mediaPlayer;
boolean started = false;
boolean prepared = false;
boolean ready=false;

private InterstitialAd mInterstitialAd;
MusicPlayerView mpv;
public static boolean autoplaytrue;
public HeadsetPlugReceiver headsetPlugReceiver;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    headsetPlugReceiver = new HeadsetPlugReceiver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("android.intent.action.HEADSET_PLUG");
    registerReceiver(headsetPlugReceiver, intentFilter);

    progressbar= findViewById(R.id.load);

    mpv = findViewById(R.id.mpv);
    mpv.setProgressVisibility(false);
    mpv.animate();

    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    mpv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (ready){
                if (started) {
                    stopService(myService);
                    mediaPlayer.pause();
                    started = false;

                    mpv.stop();
                } else {
                    startService(myService);
                    mpv.start();
                    mediaPlayer.start();
                    started = true;
                }
            }
        }
    });
    new PlayTask().execute(getResources().getString(R.string.streamlink));
}

public class HeadsetPlugReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (!Objects.equals(intent.getAction(), Intent.ACTION_HEADSET_PLUG)) {
            return;
        }

        boolean connectedHeadphones = (intent.getIntExtra("state", 0) == 1);

        if (!connectedHeadphones){
            if (ready){
                if (started) {
                    mediaPlayer.pause();
                    started = false;

                    mpv.stop();
                }
            }
        }
    }
}

@SuppressLint("StaticFieldLeak")
private class PlayTask extends AsyncTask {

    @Override
    protected Boolean doInBackground(String... strings) {

        try {
            mediaPlayer.setDataSource(strings(0));
            mediaPlayer.prepare();
            prepared = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return prepared;
    }

    @Override
    protected void onPostExecute(Boolean aBoolean) {
        super.onPostExecute(aBoolean);
        progressbar.hide();
        ready=true;
        mpv.setEnabled(true);
    }
}

@Override
protected void onDestroy() {
    if (headsetPlugReceiver != null) {
        unregisterReceiver(headsetPlugReceiver);
        headsetPlugReceiver = null;
    }
    super.onDestroy();
}

}