Callbacks on iOS and tvOS
The Arc Mobile Video module for iOS and tvOS offers a huge number of different callbacks to hook into the playerβs behavior. The callbacks are available with both the ArcMediaPlayerViewController
and the AVPlayerViewController
, though specific callbacks may only be available for certain view controllers.
By using the AVPlayerController
to control video playback (as opposed to the player view controller or AVPlayer
directly), you can register for and receive callbacks for many player and ad lifecycle events. These can be used to update your appβs UI, perform analytics, and anything else you can think of.
The tables below are split into four columns, for the two player view controllers (ArcMediaPlayerViewController
and AVPlayerViewController
), and the two supported platforms (iOS and tvOS).
All of the delegate functions have empty default implementations, so implement only the ones youβre interested in. The sample app implements them by adding entries to an event timeline table while a video plays.
AdDelegate
Implement the AdDelegate protocol to receive ad-related callbacks. You donβt need to implement these in order to report back to the ad service; the module handles that for you. Assign your implementation to the player controllerβs adController?.adDelegate
property.
For all callbacks that take an adInfo:
parameter, you can cast the value to either a MediaTailor.Avail.Ad
(in the module) or a Google IMAAd to get more information, such as the ad ID. See the sample appβs DelegateEventsViewController.logAd(_,_)
for an example.
Callbacks | Function | iOS ArcMediaPlayer | iOS AVPlayer | tvOS ArcMediaPlayer | tvOS AVPlayer |
---|---|---|---|---|---|
Ad break started (livestream only) | player(_:adBreakStarted:) | β | β | β | β |
Ad completed | player(_:adCompleted:) | β | β | β | β |
Ad break ended (livestream only) | player(_:adBreakEnded:) | β | β | β | β |
Ad error | player(_:adInfo:adError:) | β | β | β | β |
Ad started | player(_:adStarted:) | β | β | β | β |
Ad paused | player(_:adPaused:) | β | β | β | β |
Ad resumed | player(_:adResumed:) | β | β | β | β |
Ad skipped (pre-roll ads only) | player(_:adSkipped:) | β | β | β | β |
Ad played 25% | player(_:adPlayed25Percent:) | β | β | β | β |
Ad played 50% | player(_:adPlayed50Percent:) | β | β | β | β |
Ad played 75% | player(_:adPlayed75Percent:) | β | β | β | β |
Ad tapped (pre-roll ads only) | player(_:adTapped:) | β | β | β | β |
Ad impression (livestream only) | player(_:adImpression:) | β | β | β | β |
Ad clicked | player(_ player: AVPlayer, adClicked: **Any**?) | β | β | β | β |
Ad will open external application | playerAdWillOpenExternalApplication(player: AVPlayer) | β | β | β | β |
Ad will open in-app link | playerAdWillOpenInAppLink(player: AVPlayer) | β | β | β | β |
Ad did open in-app link | playerAdDidOpenInAppLink(player: AVPlayer) | β | β | β | β |
Ad will close in-app link | playerAdWillCloseInAppLink(player: AVPlayer) | β | β | β | β |
Ad did close in-app link | playerAdDidCloseInAppLink(player: AVPlayer) | β | β | β | β |
AVPlayerDelegate
Implement the AVPlayerDelegate protocol to receive callbacks for the video player and video lifecycle events. Assign your implementation to the player controllerβs delegate
property.
Note that the AVPlayerDelegate
protocol also extends the AdDelegate
protocol.
Callbacks | Function | iOS ArcMediaPlayer | iOS AVPlayer | tvOS ArcMediaPlayer | tvOS AVPlayer |
---|---|---|---|---|---|
Captions on | player(_:captionsOn:) | β | β | ||
Captions off | playerCaptionsOff(_) | β | β | ||
Current item changed | player(_:currentItemChangedFrom:) | β | β | β | β |
Player error | player(_:error:) | β | β | β | β |
Player appeared | playerAppeared(_) | β | β | ||
Player ready | playerReady(_) | β | β | β | β |
Player status unknown | player(_:statusUnknown) | β | β | β | β |
Player item error | player(_:item:error:) | β | β | β | β |
Player item ready | player(_:itemReady:) | β | β | β | β |
Player item status unknown | player(_:itemStatusUnknown:) | β | β | β | β |
Player completed (only for VOD) | player(_:completed:) | β | β | β | β |
Played 25% (only for VOD) | player(_:played25Percent:) | β | β | β | β |
Played 50% (only for VOD) | player(_:played50Percent:) | β | β | β | β |
Played 75% (only for VOD) | player(_:played75Percent:) | β | β | β | β |
Played percent (only for VOD) | player(_:item:playedPercent:) | β | β | β | β |
Player muted | playerMuted(_) | β | β | β | β |
Player unmuted | playerUnmuted(_) | β | β | β | β |
Player volume changed | player(_:volumeChangedFrom:) | β | β | β | β |
Player paused | player(_:paused:) | β | β | β | β |
Player resumed | player(_:resumed:) | β | β | β | β |
Player skipped to time | player(_:item:skippedTo:) | β | β | ||
Player started | player(_:started:byUser:) | β | β | β | β |
ArcMediaPlayerViewDelegate
Implement this protocol and assign your implementation to ArcMediaPlayerViewController
βs playerView.delegate
to get callbacks that are specific to the ArcMediaPlayerView
. Note that even though the ArcMediaPlayerView is supported on tvOS, the tvOS version does not have a control bar, so these callbacks will never get called.
Callbacks | Function | iOS ArcMediaPlayer | iOS AVPlayer | tvOS ArcMediaPlayer | tvOS AVPlayer |
---|---|---|---|---|---|
Player view controller bar will appear | playerViewControlBarWillAppear(_) | β | |||
Player view controller bar did appear | playerViewControlBarDidAppear(_) | β | |||
Player view controller bar will disappear | playerViewControlBarWillDisappear(_) | β | |||
Player view controller bar did disappear | playerViewControlBarDidDisappear(_) | β |