# StopAudio & unsubscribe from audio doesn't work

**URL:** <https://devforum.zoom.us/t/stopaudio-unsubscribe-from-audio-doesnt-work/78060>\
**Category:** iOS\
**Created:** [October 29, 2022, 6:07am UTC](https://devforum.zoom.us/t/stopaudio-unsubscribe-from-audio-doesnt-work/78060 "2022-10-29T06:07:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rokgregoric](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/rokgregoric/32/40678_2.png) [@rokgregoric](https://devforum.zoom.us/u/rokgregoric)\
**Post date:** [October 29, 2022, 6:07am UTC](https://devforum.zoom.us/t/stopaudio-unsubscribe-from-audio-doesnt-work/78060/1 "2022-10-29T06:07:41Z")

</div>

**Description**  
When starting the session with the audio disconnected:

```auto
let audioOptions = ZoomVideoSDKAudioOptions()
audioOptions.connect = false
audioOptions.mute = true

let ctx = ZoomVideoSDKSessionContext()
ctx.audioOption = audioOptions
ctx.virtualAudioMicDelegate = self
ctx.virtualAudioSpeakerDelegate = self

```

the callback:

```auto
func onOneWayAudioReceived(_ rawData: ZoomAudioRawData?, user: ZoomUser?)

```

doesn’t get called when there is audio in the session. ✅

After calling:

```auto
zoom?.getAudioHelper().startAudio()

```

The callback `onOneWayAudioReceived` gets called when there is audio in the session. ✅

At that point calling:

```auto
zoom?.getAudioHelper().stopAudio()

```

and/or also:

```auto
zoom?.getAudioHelper().subscribe() / zoom?.getAudioHelper().unSubscribe()

```

in different orders the callback `onOneWayAudioReceived` still gets called when there is audio in the session. ❌

**Which iOS Video SDK version?**  
v1.3.2  
v1.5.2

---

<div class="post-metadata">

**Author:** ![gianni.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/gianni.zoom/32/32523_2.png) [@gianni.zoom](https://devforum.zoom.us/u/gianni.zoom)\
**Post date:** [November 4, 2022, 4:41pm UTC](https://devforum.zoom.us/t/stopaudio-unsubscribe-from-audio-doesnt-work/78060/2 "2022-11-04T16:41:31Z")

</div>

Hi @rokgregoric ,

Thanks for sharing on the forum! Are you getting the user’s [`ZoomVideoSDKAudioType`](https://marketplace.zoom.us/docs/sdk/video/ios/essential/audio-and-video-options/) first per our guidance here?

Here’s the full reference: [Reference](https://marketplace.zoom.us/docs/sdk/video/ios/reference/)

---

<div class="post-metadata">

**Author:** ![rokgregoric](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/rokgregoric/32/40678_2.png) [@rokgregoric](https://devforum.zoom.us/u/rokgregoric)\
**Post date:** [November 5, 2022, 3:02am UTC](https://devforum.zoom.us/t/stopaudio-unsubscribe-from-audio-doesnt-work/78060/3 "2022-11-05T03:02:55Z")

</div>

Hi @gianni.zoom,  
The audioType works correctly. And YES I check the `audioType` before starting/stopping audio.

Before I start audio I see:

```auto
me?.audioStatus()?.audioType == .None

```

after starting audio I see:

```auto
me?.audioStatus()?.audioType == .VOIP

```

and after stopping audio I see:

```auto
me?.audioStatus()?.audioType == .None

```

but the callbacks are still being called.

---

<div class="post-metadata">

**Author:** ![rokgregoric](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/rokgregoric/32/40678_2.png) [@rokgregoric](https://devforum.zoom.us/u/rokgregoric)\
**Post date:** [November 5, 2022, 3:12am UTC](https://devforum.zoom.us/t/stopaudio-unsubscribe-from-audio-doesnt-work/78060/4 "2022-11-05T03:12:05Z")

</div>

as a reference … here is a code snippet that explains how I change states:

```auto
/// start+unmute / mute+stop audio
private func set(audio enabled: Bool) {
  if enabled {
    if me?.audioStarted == false {
      shouldUnmuteAudio = true
      audio(start: true)
    } else if unmute {
      audio(mute: false)
    }
  } else {
    if me?.audioStarted == true {
      if me?.audioMuted == true {
        audio(start: false)
      } else {
        shouldStopAudio = true
        audio(mute: true)
      }
    }
  }
}

private func audioDidChange() {
  DispatchQueue.main.async(execute: audioFixes)
}

private var shouldUnmuteAudio = false
private var shouldStopAudio = false

private func audioFixes() {
  if shouldUnmuteAudio {
    shouldUnmuteAudio = false
    audio(mute: false)
  } else if shouldStopAudio {
    shouldStopAudio = false
    audio(start: false)
  }
}

func onUserAudioStatusChanged(_ helper: ZoomVideoSDKAudioHelper?, user userArray: [ZoomVideoSDKUser]?) {
  audioDidChange()
}

extension ZoomVideoSDKUser {
  var audioStarted: Bool { audioStatus()?.audioType == .VOIP }
  var audioMuted: Bool { audioStatus()?.isMuted == true }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [December 5, 2022, 1:13pm UTC](https://devforum.zoom.us/t/stopaudio-unsubscribe-from-audio-doesnt-work/78060/5 "2022-12-05T13:13:02Z")

</div>

Closed on December 5, 2022, 1:13pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
