Swift
Control audio via Session Events
Finally, use the Vonage session delegate methods to handle the ringtone. After publishing the video, the doPublish method triggers the ringtone start. When the self-subscribing stream connects, the subscriberDidConnectToStream method stops the ringtone.
extension VonageVideoManager: OTPublisherDelegate {
func publisher(_ publisher: OTPublisherKit, streamCreated stream: OTStream) {
print("Publishing")
// play the ringtone for 10 seconds , it is fun...
// doSubscribe method will stop it later
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
self.doSubscribe(stream)
}
}
func publisher(_ publisher: OTPublisherKit, streamDestroyed stream: OTStream) {
print("publisher \(publisher) streamDestroyed \(stream)")
if let subStream = subscriber?.stream, subStream.streamId == stream.streamId {
cleanupSubscriber()
}
cleanupPublisher()
}
func publisher(_ publisher: OTPublisherKit, didFailWithError error: OTError) {
print("publisher didFailWithError \(error)")
cleanupPublisher()
}
}
extension VonageVideoManager: OTSubscriberDelegate {
func subscriberDidConnect(toStream subscriberKit: OTSubscriberKit) {
print("subscriberDidConnectToStream (\(subscriber?.stream?.connection.connectionId ?? ""))")
// Stop ringtone from playing, as the subscriber will connect shortly
myAudioDevice?.stopRingtone()
guard let view = self.subscriber?.view else { return }
subView = AnyView(Wrap(view))
}
func subscriber(_ subscriber: OTSubscriberKit, didFailWithError error: OTError) {
print("Subscriber failed: \(error.localizedDescription)")
}
}
Custom audio driver
Learn how to use a custom audio driver to customize publisher and subscriber stream audio. You will use the custom audio driver when you want to start and stop the audio, and play your own audio file. When you want to do "anything" with audio, other than the SDK default behavior of live video chat, you would use custom audio drivers.
Available on:
Steps
1
Introduction2
Getting Started3
Creating a New Project4
Adding the Vonage Video SDK5
Setting Up Authentication6
Overview7
Create the Custom Audio Driver Class8
Implement the "Play Ringtone" Logic9
Implement the "Stop Ringtone" Logic10
Integrate with Vonage Video Manager11
Control audio via Session Events12
How It Works13
Conclusion