};
var _soundModeChangeListener;
+var _currentSoundMode;
+var _isFirstSoundModeChange = true;
+// Native side sometimes fires sound change callback two times in a row
+// with different values of sound mode. One of this value is only transitional
+// value caused by hazard of two values which should change simultaneously.
+// By waiting whether second callback would fire we bypass this problem.
function _soundModeChangeListenerCallback(result) {
- native_.callIfPossible(_soundModeChangeListener, native_.getResultObject(result));
+ _currentSoundMode = result;
+ if (_isFirstSoundModeChange) {
+ _isFirstSoundModeChange = false;
+ setTimeout(function () {
+ _isFirstSoundModeChange = true;
+ native_.callIfPossible(_soundModeChangeListener, native_.getResultObject(_currentSoundMode));
+ }, 100);
+ }
}
SoundManager.prototype.setSoundModeChangeListener = function(callback) {
void SoundInstance::OnSoundModeChange(const std::string& newmode) {
ScopeLogger();
+ if (current_sound_mode == newmode) {
+ LoggerD("New sound mode equals to current sound mode");
+ return;
+ }
+ current_sound_mode = newmode;
picojson::value event = picojson::value(picojson::object());
picojson::object& obj = event.get<picojson::object>();
picojson::value result = picojson::value(newmode);
void OnSoundModeChange(const std::string& newmode);
SoundManager manager_;
+
+ // It is used in OnSoundModeChange function to prevent double firing of callback
+ std::string current_sound_mode;
};
} // namespace sound