<img src="https://img.shields.io/badge/%20-ENTERPRISE-B10031" style="float:left"/><br />

ο»Ώ

When using this callback, be mindful of the following points:

  • Provide a response to the completion handler in all logical paths. Failing to do so can cause unpredictable behavior due to the blocking nature of the callback.

  • Use a `weak` reference to `self` in the callback block to avoid creating a retain cycle.

<br />

The `setPlaylistItemCallback(_:)` method enables you to play (unchanged or modified in real-time) or skip an upcoming playlist item. In addition, you can execute relevant asynchronous code, such as reporting to a server or updating the UI.

The method passes in the upcoming item, its position in the playlist, and the completion block for you to inform the player of your decision.

<br />

ο»Ώ
ArgumentDescription
**completion** JWPlayerItemCompletionClosure that informs the player of your decision Pass `nil` to skip or a `JWPlayerItem` to play (unchanged or modified).
**index** IntPosition of `item` in the playlist
**item** JWPlayerItemUpcoming item in the playlist

<br />


ο»Ώ

## Example Scenario

Imagine developing a news streaming app. This app has a playlist that plays top news videos back-to-back. Viewers can also specify categories of news videos to skip.

You want to keep users engaged and informed, and you want to monetize the app through ads. You recognize that bombarding users with ads isn't user-friendly, especially when watching breaking news.

<br />

### Solution

The `setPlaylistItemCallback(_:)` method can handle each condition:

  • **Regular News**: Play a preroll ad before the segment.

  • **User Preferences**: For a viewer who prefers not to watch entertainment news, skip all entertainment news videos.

  • **Breaking News**: Play the segment without ads for news segments bearing the "Breaking News:" prefix and display a breaking news banner to the user.

ο»Ώ

ο»Ώ

In your production code, use robust error handling instead of using `try!`.

<br />

<!-- Removes the automatic page-to-page navigation at the bottom of the page -->

<style> .rm-Pagination { display: none; } </style>