Beispiel #1
0
  void updateConnectionState() {
    final int oldState = serviceState;

    switch (state) {
      case MumbleConnectionHost.STATE_CONNECTING:
        serviceState = CONNECTION_STATE_CONNECTING;
        break;
      case MumbleConnectionHost.STATE_CONNECTED:
        settings.addObserver(this);
        serviceState = synced ? CONNECTION_STATE_CONNECTED : CONNECTION_STATE_SYNCHRONIZING;
        if (settings.isDeafened()) {
          setDeafened(true);
        } else if (settings.isMuted()) {
          setMuted(true);
        }
        updateFavourites();
        if (synced) {
          // Initialize audio input
          mAudioInput = new AudioInput(this, mProtocol.codec);
          if (settings.isVoiceActivity())
            mAudioInput.startRecording(); // Immediately begin record if using voice activity

          showNotification();
        }
        break;
      case MumbleConnectionHost.STATE_DISCONNECTED:
        settings.deleteObserver(this);
        serviceState = CONNECTION_STATE_DISCONNECTED;
        if (mAudioInput != null) {
          try {
            mAudioInput.stopRecordingAndBlock();
          } catch (InterruptedException e) {
            e.printStackTrace();
          } finally {
            mAudioInput.terminate();
            mAudioInput = null;
          }
        }
        hideNotification();
        break;
      default:
        Assert.fail();
    }

    if (oldState != serviceState) {
      broadcastState();
    }
  }