When the application is reconnected, ‘setup’ operates again.
How to operate ‘SETUP’ only once?
void setup(){
s1 = new MediaPlayer();
s2 = new MediaPlayer();
af1 = context.getAssets().openFd("1.mp3");
af2 = context.getAssets().openFd("2.mp3");
s1.setDataSource(af1.getFileDescriptor(), af1.getStartOffset(), af1.getLength());
s2.setDataSource(af2.getFileDescriptor(), af2.getStartOffset(), af2.getLength());
s1.prepare();
s2.prepare();
}
-
Run the created ‘APP’ on your smartphone. It works normally.
-
It appears on the background screen for a while, then reconnects to the ‘APP’.
-
‘setup’ restarts, so it seems that mp3 files are duplicated twice in s1 and af1.
-
The same sound source is played twice.
-
Is there a way to prevent setup from working even after leaving the ‘APP’ screen?
boolean setup_en = true;
void setup(){
if(setup_en){ setup_en = false;
s1 = new MediaPlayer();
s2 = new MediaPlayer();
af1 = context.getAssets().openFd("1.mp3");
af2 = context.getAssets().openFd("2.mp3");
s1.setDataSource(af1.getFileDescriptor(), af1.getStartOffset(), af1.getLength());
s2.setDataSource(af2.getFileDescriptor(), af2.getStartOffset(), af2.getLength());
s1.prepare();
s2.prepare();
}
}
It can’t be solved with the above method, right?