Events & Listeners Basics - 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);
                    
Next Step

In the next step you'll learn more about available events in Player Events guide.

Support Needed?

Create a free ticket and our support team will provide you necessary assistance.