OpentTok (iOS) How to subscribe to hasAudio stream changes

ぐ巨炮叔叔 提交于 2019-12-11 18:07:18

问题


I need a possibility in the TokBox iOS SDK to find out if a subscribed stream has audio dynamically / via an event. (OTStream.hasAudio)

OTSubscriberDelegate provides callbacks for the subscribed video state subscriberVideoEnabled/Disabled but I can't find anything for audio.

  • The JS SDK provides the StreamPropertyChangedEvent for this.
  • The Android SDK provides the StreamPropertiesListener for this.
  • iOS seems to be the only platform that doesn't have a proper solution.

回答1:


TokBox Developer Evangelist here.

For the iOS SDK, we don't provide a delegate for stream property changes, but you can implement key value observing(KVO) to check if the observed stream property has changed.

In the example below, I added an observer for the hasAudio stream property and the observer will print the old and new values whenever it changes.

 func session(_ session: OTSession, streamCreated stream: OTStream) {
   let hasAudioObservation: NSKeyValueObservation = stream.observe(\.hasAudio, options: [.old, .new]) { object, change in
     guard let oldValue = change.oldValue else { return }
     guard let newValue = change.newValue else { return }
     print("Old stream value: \(oldValue)")
     print("New stream value: \(newValue)")
}


来源:https://stackoverflow.com/questions/51157636/openttok-ios-how-to-subscribe-to-hasaudio-stream-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!