I'm new to android, and working on a project where I have to implement background music in our app. I've already implemented background music using service, the problem is: I don't know how to change the volume of the music dynamically using a seekbar from an activity.
My service looks like this:
package hu.szoftverprojekt.holdemfree.controller;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import androidx.annotation.Nullable;
import hu.szoftverprojekt.holdemfree.R;
public class PlaySound extends Service {
MediaPlayer player;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
player=MediaPlayer.create(this, R.raw.ss);
player.setLooping(true);
player.start();
player.setVolume(SettingsScreen.volume, SettingsScreen.volume);
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
player.stop();
}
}