Attaching and detaching observers - Storm iOS Library

Adding an observer consists in calling the function stormLibrary.addObserver(observer), where an observer is the class that implements the StormLibraryObserver protocol.

Attaching an observer

In the example below, we implemented the onVideoConnecting() and onVideoPlay() methods causing the console to display "connecting" message when Storm Library connects to the Storm server, and "play" when starting video playback.

                        
class StormImpl : StormLibraryObserver{

    public var stormLibrary : StormLibrary

    init() {

        stormLibrary = StormLibrary()
        stormLibrary.addObserver(self)
        stormLibrary.addStormMediaItem(stormMediaItem: StormMediaItem(host: "sub1.domain.com", port: 443, isSSL: true, applicationName: "live", streamName: "test_hd", label: "720p", isSelected: true))
        try! stormLibrary.play()

    }

    func onVideoConnecting() {
        print("connecting")
    }

    func onVideoPlay() {
        print("play")
    }

}
                    

A full list of events can be found in Library Events section and Video Events section.

Detaching an observer

In order to detach (remove) an event listener (observer) just use:

                        
stormLibrary.removeObserver(observerObject);