Event Listeners Reference (iOS)

The JWP iOS SDK contains delegate methods created to listen for events. The following sections describe each delegate method.



Ads

πŸ“˜

When using the JWPlayerView, your must supply your own delegate to the JWPlayer object.


jwplayer(_: adEvent:)

Reports when an event is emitted by the player

class PlayerViewController: JWPlayerViewController {
     // This example assumes you have created a config for your player.

     override func jwplayer(_ player: JWPlayer, adEvent event: JWAdEvent) {
          switch event.type {
          case .impression:
               guard let tag = event[.tag] as? URL else {
                    break
               } 

               // Handle tag or other properties here.
          default:
               break
          }
     } 
}
class PlayerViewController: UIViewController, JWAdDelegate {
     // This example assumes you have created a JWPlayerView in a storyboard or XIB.
     @IBOutlet var playerView: JWPlayerView!

     override func viewDidLoad() {
          super.viewDidLoad()

          // This example assumes you have created a config for your player. This is covered in other documentation.

          playerView.player.adDelegate = self
     }

     override func jwplayer(_ player: JWPlayer, adEvent event: JWAdEvent) {
          switch event.type {
          case .impression:
               guard let tag = event[.tag] as? URL else {
                    break
               } 

               // Handle tag or other properties here.
          default:
               break
          }
     } 
}

Learn about the information contained in the JWAdEvent class.



Chapters

πŸ“˜

When using the JWPlayerView, your must supply your own delegate to the JWPlayer object.


jwplayer(_: beganChapter chapter:)

Called when a chapter begins and contains a description of the chapter

// Subclass of JWPlayerViewController
class PlayerViewController: JWPlayerViewController {
    
    override func jwplayer(_ player: JWPlayer, beganChapter chapter: JWCue) {
        // Always be sure to inform the superclass of the event so
        // the user interface updates.
        super.jwplayer(player, beganChapter: chapter)
        
        // Handle the event here.
    }
}
// A custom chapters delegate
class ChapterDelegate: JWChaptersDelegate {
    
    func jwplayer(_ player: JWPlayer, beganChapter chapter: JWCue) {
        // Handle the event here.
    }
}

// Assume this delegate is declared in a class you designed.
let chaptersDelegate = ChaptersDelegate()

// Your custom method for setting up your chapter observer.
func yourSetupMethod(view: JWPlayerView) {
    let player = view.player
    let player.chaptersDelegate = chaptersDelegate
}

Learn about the information contained in the JWCue class.



jwplayer(_:endedChapter:)

Called when a chapter ends and contains a description of the chapter

// Subclass of JWPlayerViewController
class PlayerViewController: JWPlayerViewController {
    
    override func jwplayer(_ player: JWPlayer, endedChapter chapter: JWCue) {
        // Always be sure to inform the superclass of the event so
        // the user interface updates.
        super.jwplayer(player, endedChapter: chapter)
        
        // Handle the event here.
    }
}
// A custom chapters delegate
class ChapterDelegate: JWChaptersDelegate {
    
    func jwplayer(_ player: JWPlayer, endedChapter chapter: JWCue) {
        // Handle the event here.
    }
}

// Assume this delegate is declared in a class you designed.
let chaptersDelegate = ChaptersDelegate()

// Your custom method for setting up your chapter observer.
func yourSetupMethod(view: JWPlayerView) {
    let player = view.player
    let player.chaptersDelegate = chaptersDelegate
}

Learn about the information contained in the JWCue class.



jwplayer(_: loadedChapters:)

Called when the chapters are loaded for the currently playing content

// Subclass of JWPlayerViewController
class PlayerViewController: JWPlayerViewController {
    
    override func jwplayer(_ player: JWPlayer, loadedChapters chapter: JWCue) {
        // Always be sure to inform the superclass of the event so
        // the user interface updates.
        super.jwplayer(player, loadedChapters: chapter)
        
        // Handle the event here.
    }
}
// A custom chapters delegate
class ChapterDelegate: JWChaptersDelegate {
    
    func jwplayer(_ player: JWPlayer, loadedChapters chapter: JWCue) {
        // Handle the event here.
    }
}

// Assume this delegate is declared in a class you designed.
let chaptersDelegate = ChaptersDelegate()

// Your custom method for setting up your chapter observer.
func yourSetupMethod(view: JWPlayerView) {
    let player = view.player
    let player.chaptersDelegate = chaptersDelegate
}

Learn about the information contained in the JWCue class.



Metadata

By listening to metadata events, you can gather more information about the playing content or response to custom cues. Each metadata class contains unique media information.

πŸ“˜

When using the JWPlayerView, your class my conform to a specific metadata delegate.


jwplayer(_:dateRangeMetadata metadata:)

Triggered when the content has entered the date range defined by the metadata cue

// Subclass of JWPlayerViewController
class PlayerViewController: JWPlayerViewController {
    
    override func jwplayer(_ player: JWPlayer, dateRangeMetadata metadata: JWDateRangeMetadata) {
        // Always be sure to inform the superclass of the event so
        // the user interface updates.
        super.jwplayer(player, dateRangeMetadata: metadata)
        
        // Handle the event here.
    }
}
class ID3MetadataDelegate: JWID3MetadataDelegate {
     func jwplayer(_ player: JWPlayer, id3Metadata metadata: JWID3Metadata)
}

class PlayerViewController: UIViewController {
     @IBOutlet var playerView: JWPlayerView! // Your player view
     let <var delegateName> = <JWDelegateName>()

     override func viewDidLoad() {
          playerView.metadataDelegates.<JWMetadataDelegates> = <var delegateName>
     }
}

Learn about the information contained in the JWDateRangeMetadata class.



jwplayer(_: dateRangeMetadataCueParsed metadata:)

Triggered when the metadata has been parsed and buffered

// Subclass of JWPlayerViewController
class PlayerViewController: JWPlayerViewController {
    
    override func jwplayer(_ player: JWPlayer, dateRangeMetadataCueParsed metadata: JWDateRangeMetadata) {
        // Always be sure to inform the superclass of the event so
        // the user interface updates.
        super.jwplayer(player, dateRangeMetadataCueParsed: metadata)
        
        // Handle the event here.
    }
}
class ID3MetadataDelegate: JWID3MetadataDelegate {
     func jwplayer(_ player: JWPlayer, id3Metadata metadata: JWID3Metadata)
}

class PlayerViewController: UIViewController {
     @IBOutlet var playerView: JWPlayerView! // Your player view
     let <var delegateName> = <JWDelegateName>()

     override func viewDidLoad() {
          playerView.metadataDelegates.<JWMetadataDelegates> = <var delegateName>
     }
}

Learn about the information contained in the JWDateRangeMetadata class.



Related

By listening to related methods, you can be informed about the following types of events:

  • A related (Recommendations) playlist has been loaded by the player.
  • The next item has been loaded and is ready for playback
  • A related item has begun playing.

If you are handling these events with the intent to create your own user interface, call the play(relatedContent:) in the JWPlayer object after a specific related item has been chosen for playback.

πŸ“˜

When using the JWPlayerView, your must supply your own delegate to the JWPlayer object.


jwplayer(_:loadedNextUpItem:)

Occurs when the next up item has been loaded

As an argument, it supplies a description of the item.

// Subclass of JWPlayerViewController
class PlayerViewController: JWPlayerViewController {
    
     override func jwplayer(_ player: JWPlayer, loadedNextUpItem item: JWCue) {
        // Always be sure to inform the superclass of the event so
        // the user interface updates.
        super.jwplayer(player, loadedNextUpItem: item)
        
        // Handle the event here.
    }
}
// A custom related content event delegate
class RelatedContentEventDelegate: JWRelatedEventDelegate {
    
     override func jwplayer(_ player: JWPlayer, loadedNextUpItem item: JWCue) {
        // Handle the event here.
    }
}

// Assume this delegate is declared in a class you designed.
let relatedEventDelegate = RelatedContentEventDelegate()

// Your custom method for setting up your related content event observer.
func yourSetupMethod(view: JWPlayerView) {
    let player = view.player
    let player.relatedEventDelegate = relatedEventDelegate
}

Learn about the information contained in the JWCue class.



jwplayer(_:loadedRelatedPlaylist:)

Occurs when the playlist of related content is loaded

As an argument, it supplies the playlist.

// Subclass of JWPlayerViewController
class PlayerViewController: JWPlayerViewController {
    
    override func jwplayer(_ player: JWPlayer, loadedRelatedPlaylist playlist: [JWPlayerItem]) {
        // Always be sure to inform the superclass of the event so
        // the user interface updates.
        super.jwplayer(player, loadedRelatedPlaylist: playlist)
        
        // Handle the event here.
    }
}
// A custom related content event delegate
class RelatedContentEventDelegate: JWRelatedEventDelegate {
    
    override func jwplayer(_ player: JWPlayer, loadedRelatedPlaylist playlist: [JWPlayerItem]) {
        // Handle the event here.
    }
}

// Assume this delegate is declared in a class you designed.
let relatedEventDelegate = RelatedContentEventDelegate()

// Your custom method for setting up your related content event observer.
func yourSetupMethod(view: JWPlayerView) {
    let player = view.player
    let player.relatedEventDelegate = relatedEventDelegate
}

Learn about the information contained in the JWPlayerItem class.



jwplayer(_:relatedItemBeganPlaying:atIndex:withMethod:)

Occurs when a related item has begun playing

As an argument, it supplies the index of the item in the playlist and what method was used to play the item.

// Subclass of JWPlayerViewController
class PlayerViewController: JWPlayerViewController {
    
    override func jwplayer(_ player: JWPlayer, relatedItemBeganPlaying item: JWPlayerItem, atIndex index: Int, withMethod method: JWRelatedInteraction) {
        // Always be sure to inform the superclass of the event so
        // the user interface updates.
        super.jwplayer(player, relatedItemBeganPlaying: item, atIndex: index, withMethod: method)
        
        // Handle the event here.
    }
}
// A custom related content event delegate
class RelatedContentEventDelegate: JWRelatedEventDelegate {
    
    override func jwplayer(_ player: JWPlayer, relatedItemBeganPlaying item: JWPlayerItem, atIndex index: Int, withMethod method: JWRelatedInteraction) {
       // Handle the event here.
    }
}

// Assume this delegate is declared in a class you designed.
let relatedEventDelegate = RelatedContentEventDelegate()

// Your custom method for setting up your related content event observer.
func yourSetupMethod(view: JWPlayerView) {
    let player = view.player
    let player.relatedEventDelegate = relatedEventDelegate
}

Learn about the information contained in the JWPlayerItem class.



© 2007-2024 Longtail Ad Solutions, Inc.