When I try to start a sound in my application it doesn't play. I have seen that the method does get called however soundPool just doesn't want to play the sound. The app starts as intended, however, it just doesn't want to play the queued sound. Is it something I am doing wrong? is the music file I am trying to play just too large? (35.4MB)
Any input is appreciated!
StartActivity (relevant bit)
public class StartActivity extends AppCompatActivity {
private Button startButton;
//Sounds
private SoundManager soundManager;
private int ambient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start_activity);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
startButton = (Button) findViewById(R.id.startButton);
//Setting Up sounds
soundManager = new SoundManager(this);
ambient = soundManager.getSoundID(R.raw.music_ambient);
soundManager.playLoop(ambient);
Application.setSoundManager(soundManager);
Application
public class Application {
public static SoundManager soundManager;
public static SoundManager getSoundManager() {
return soundManager;
}
public static void setSoundManager(SoundManager soundManagerIns) {
soundManager = soundManagerIns;
}
}
SoundManager class
import android.content.Context;
import android.media.SoundPool;
import android.util.Log;
public class SoundManager {
private Context context;
private SoundPool soundPool;
private boolean isPlaying = false;
SoundManager(Context context) {
this.context = context;
SoundPool.Builder builder = new SoundPool.Builder();
builder.setMaxStreams(10);
soundPool = builder.build();
}
int getSoundID(int resourcesID) {
return (soundPool.load(context, resourcesID, 1));
}
void play(int soundId) {
soundPool.play(soundId, 1, 1, 1, 0, 1);
}
void playLoop(int soundId){
if(!isPlaying) {
Log.d("LEADER", "called this");
soundPool.play(soundId, 1, 1, 1, -1, 1);
isPlaying = true;
}
}
void stop(int soundId){
isPlaying = false;
soundPool.stop(soundId);
}
}