Commit 6b3ab98a by pye52

1、优化退到后台再回到主界面会无声的问题

2、保证NetworkUtils只初始化一次
parent d5045697
......@@ -6,6 +6,7 @@ import androidx.annotation.NonNull;
import androidx.work.Configuration;
import com.bgycc.smartcanteen.executor.SCTaskExecutor;
import com.bgycc.smartcanteen.utils.NetworkUtils;
import com.blankj.utilcode.util.CrashUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.PathUtils;
......@@ -31,6 +32,7 @@ public class RootApp extends Application implements Configuration.Provider {
.setBorderSwitch(false)
.setFilePrefix(LOG_PREFIX)
.setSaveDays(LOG_SAVE_DAYS);
NetworkUtils.initialize(this);
}
@NonNull
......
......@@ -97,7 +97,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
deviceSN = SmartCanteenUtils.getDeviceSN(newBase.getApplicationContext());
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
TTSHelper.initialize(newBase.getApplicationContext());
NetworkUtils.initialize(newBase.getApplicationContext());
if (deviceSN.isEmpty()) {
LogUtils.file(TAG, "设备SN号为空");
......
......@@ -19,10 +19,10 @@ import static com.bgycc.smartcanteen.utils.SmartCanteenUtils.TAG;
public class TTSHelper {
private static boolean mSupportTTS = false;
private static TextToSpeech mTTS = null;
private static final SoundPool mSoundPool;
private static SoundPool mSoundPool;
private static final HashMap<String, Integer> mSoundIdMap = new HashMap<>();
static {
public static void initialize(Context context) {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
......@@ -31,9 +31,6 @@ public class TTSHelper {
mSoundPool = new SoundPool.Builder()
.setAudioAttributes(audioAttributes)
.build();
}
public static void initialize(Context context) {
mSoundPool.setOnLoadCompleteListener((soundPool, sampleId, status) -> {
if (status == 0) {
soundPool.play(sampleId, 1f, 1f, 100, 0, 1f);
......@@ -45,6 +42,7 @@ public class TTSHelper {
mSupportTTS = result >= TextToSpeech.LANG_AVAILABLE;
}
});
mSoundIdMap.clear();
}
public static void speak(String msg) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment