Attaching and detaching observers - Storm iOS Player

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

Attaching an observer

In the example below, we implemented the onPlayClicked () and onPauseClicked () methods causing the console to display "play clicked" and "pause clicked" messages when play & pause buttons are clicked.

                        
class StormImpl : StormPlayerViewObserver{


    public var stormLibrary : StormLibrary
    public var stormPlayer : StormPlayer

    init() {

        stormLibrary = StormLibrary()
        stormPlayer = StormPlayer(stormLibrary: stormLibrary)

        stormPlayer.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 onPlayClicked() {
        print("play clicked")
    }

    func onPauseClicked() {
        print("pause clicked")
    }
}

                    

A full list of library events can be found here.

Detaching an observer

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

                        
stormPlayer.removeObserver(observerObject);