### Install Dependencies via Carthage Source: https://github.com/npaw/avplayer-adapter-ios/blob/master/README.md Instructions for installing project dependencies using Carthage. This involves updating Carthage dependencies and potentially modifying the carthage file to select specific P2P providers. It also provides workarounds for common issues like Streamroot installation problems and Swift header not found errors. ```bash carthage update && cd Samples && carthage update ``` -------------------------------- ### Install Dependencies via CocoaPods Source: https://github.com/npaw/avplayer-adapter-ios/blob/master/README.md Instructions for installing project dependencies using CocoaPods. This includes running 'pod install' and modifying the Podfile to select specific P2P providers (Streamroot or Polynet). It also outlines necessary changes in Xcode project settings and compiler version requirements. ```bash pod install ``` -------------------------------- ### Install YouboraAVPlayerAdapter via Carthage Source: https://github.com/npaw/avplayer-adapter-ios/blob/master/README.md This snippet demonstrates how to install the YouboraAVPlayerAdapter using Carthage. Add the framework to your Cartfile, run 'carthage update', and then configure your project's Build Settings to include the Carthage build directory. ```bash github "NPAW/avplayer-adapter-ios" carthage update // Then in Xcode: // {YOUR_SCHEME} > Build Settings > Framework Search Paths // Add: $(PROJECT_DIR)/Carthage/Build/{iOS, Mac, tvOS or the platform of your scheme} ``` -------------------------------- ### Install YouboraAVPlayerAdapter via CocoaPods Source: https://github.com/npaw/avplayer-adapter-ios/blob/master/README.md This snippet shows how to add the YouboraAVPlayerAdapter to your project using CocoaPods. It includes options for the base adapter, Streamroot integration, and System73 (Polynet) integration. After adding the pod to your Podfile, run 'pod install'. ```bash pod 'YouboraAVPlayerAdapter' pod 'YouboraAVPlayerAdapter/Streamroot' pod 'YouboraAVPlayerAdapter/Polynet' pod install ``` -------------------------------- ### Setup Content Player and Ads Adapter in Swift Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Initializes the Youbora plugin with content options, sets up the AVPlayer for content, and attaches the YBAVPlayerAdapter. This is the foundational step for integrating Youbora analytics with AVPlayer content. ```swift import UIKit import AVKit import YouboraLib import YouboraAVPlayerAdapter class PlayerWithAdsViewController: UIViewController { var plugin: YBPlugin? var contentPlayer: AVPlayer? var adsPlayer: AVPlayer? var adsPlayerViewController: AVPlayerViewController? override func viewDidLoad() { super.viewDidLoad() // Setup plugin with content options let options = YBOptions() options.accountCode = "your-account-code" options.contentResource = "https://example.com/content.m3u8" options.contentIsLive = NSNumber(value: false) self.plugin = YBPlugin(options: options) // Setup content player and adapter guard let contentUrl = URL(string: options.contentResource ?? "") else { return } self.contentPlayer = AVPlayer(url: contentUrl) let contentAdapter = YBAVPlayerAdapter(player: contentPlayer!) self.plugin?.adapter = YBAVPlayerAdapterSwiftTranformer.transform(from: contentAdapter) } // ... other methods ... override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) if isMovingFromParent { plugin?.fireStop() plugin?.removeAdapter() plugin?.removeAdsAdapter() } } } ``` -------------------------------- ### Install YouboraAVPlayerAdapter with CocoaPods Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Installs the YouboraAVPlayerAdapter and its CDN integrations (Streamroot, Polynet) using the CocoaPods dependency manager. Ensure you run 'pod install' after updating your Podfile. ```ruby # Standard installation in Podfile pod 'YouboraAVPlayerAdapter' # For Streamroot CDN integration pod 'YouboraAVPlayerAdapter/Streamroot' # For Polynet/System73 CDN integration pod 'YouboraAVPlayerAdapter/Polynet' ``` ```bash # Install dependencies pod install ``` -------------------------------- ### Install YouboraAVPlayerAdapter with Swift Package Manager Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Adds the YouboraAVPlayerAdapter to your project using Swift Package Manager. Specify the repository URL and version constraints in your Package.swift file. ```swift import PackageDescription let package = Package( name: "YourApp", platforms: [ .iOS(.v12), .tvOS(.v12), .macOS(.v10_15) ], dependencies: [ .package(url: "https://bitbucket.org/npaw/avplayer-adapter-ios.git", .upToNextMajor(from: "6.7.5")) ], targets: [ .target( name: "YourApp", dependencies: ["YouboraAVPlayerAdapter"] // Ensure this matches the actual target name if different ) ] ) ``` -------------------------------- ### Initialize and Attach YBAVPlayerAdapter in Swift Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Demonstrates how to initialize the YBAVPlayerAdapter with an AVPlayer instance and attach it to a Youbora plugin in Swift. This setup is crucial for enabling playback analytics. ```swift import UIKit import AVKit import YouboraLib import YouboraAVPlayerAdapter class PlayerViewController: UIViewController { var plugin: YBPlugin? var playerViewController: AVPlayerViewController? override func viewDidLoad() { super.viewDidLoad() // Setup analytics options let options = YBOptions() options.accountCode = "your-account-code" options.contentResource = "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8" options.contentIsLive = NSNumber(value: false) self.plugin = YBPlugin(options: options) // Create AVPlayer guard let url = URL(string: options.contentResource ?? "") else { return } let player = AVPlayer(url: url) // Setup player view controller self.playerViewController = AVPlayerViewController() self.playerViewController?.player = player addChild(playerViewController!) view.addSubview(playerViewController!.view) playerViewController!.view.frame = view.bounds // Create and attach the adapter (Swift requires transformer) let adapter = YBAVPlayerAdapter(player: player) self.plugin?.adapter = YBAVPlayerAdapterSwiftTranformer.transform(from: adapter) // Start playback player.play() } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) if isMovingFromParent { // Clean up adapters to avoid retain cycles plugin?.fireStop() plugin?.removeAdapter() } } } ``` -------------------------------- ### Initialize Youbora Plugin and Options (Swift) Source: https://github.com/npaw/avplayer-adapter-ios/blob/master/README.md This Swift code demonstrates how to configure and initialize the Youbora plugin. It defines a `YBOptions` object with essential parameters like `contentResource`, `accountCode`, `adResource`, and `contentIsLive`, then uses these options to create a `YBPlugin` instance. ```swift import YouboraLib //Config Options and init plugin (do it just once for each play session) var options: YBOptions { let options = YBOptions() options.contentResource = "http://example.com" options.accountCode = "accountCode" options.adResource = "http://example.com" options.contentIsLive = NSNumber(value: false) return options; } lazy var plugin = YBPlugin(options: self.options) ``` -------------------------------- ### Initialize Youbora Plugin and Options (Objective-C) Source: https://github.com/npaw/avplayer-adapter-ios/blob/master/README.md This Objective-C code shows the initialization of the Youbora plugin. It creates a `YBOptions` object, setting properties such as `offline`, `contentResource`, `accountCode`, `adResource`, and `contentIsLive`. Finally, it instantiates `YBPlugin` with the configured options. ```objectivec //Import #import // Declare the properties @property YBPlugin *plugin; //Config Options and init plugin (do it just once for each play session) YBOptions *options = [YBOptions new]; options.offline = false; options.contentResource = resource.resourceLink; options.accountCode = @"powerdev"; options.adResource = self.ad?.adLink; options.contentIsLive = [[NSNumber alloc] initWithBool: resource.isLive]; self.plugin = [[YBPlugin alloc] initWithOptions:self.options]; ``` -------------------------------- ### Initialize and Manage AVPlayer Adapter in Objective-C Source: https://github.com/npaw/avplayer-adapter-ios/blob/master/README.md Demonstrates how to initialize the YBAVPlayerPolynetAdapter with a player and PolyNet instance, and how to properly fire stop and remove the adapter when the view is destroyed to prevent retain cycles. This adapter allows passing the polynet delegate by reference. ```objectivec #import ... //Once you have your player, polynet and plugin initialized you can set the adapter [self.plugin setAdapter:[[YBAVPlayerPolynetAdapter alloc] initWithPolyNet:polynet player:player andDelegate:polynetDelegate]]; ... // When the view gonna be destroyed you can force stop and clean the adapters in order to make sure you avoid retain cycles [self.plugin fireStop]; [self.plugin removeAdapter]; ``` -------------------------------- ### Configure Live Content Streaming with AVPlayer Adapter for iOS Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Explains how to set up the AVPlayer adapter for live streaming content. It involves configuring Youbora options to mark content as live and notes that duration metrics are not applicable for live streams. ```swift import AVFoundation import YouboraLib import YouboraAVPlayerAdapter class LiveStreamPlayer { var plugin: YBPlugin? func setupLiveStream(liveUrl: String) { let options = YBOptions() options.accountCode = "your-account-code" options.contentResource = liveUrl options.contentIsLive = NSNumber(value: true) // Mark as live content options.contentTitle = "Live Event Stream" // Live streams don't have duration // Duration will be returned as nil by the adapter self.plugin = YBPlugin(options: options) guard let url = URL(string: liveUrl) else { return } let player = AVPlayer(url: url) let adapter = YBAVPlayerAdapter(player: player) self.plugin?.adapter = YBAVPlayerAdapterSwiftTranformer.transform(from: adapter) player.play() // For iOS 13+, latency metrics are automatically captured // via minimumTimeOffsetFromLive property } } // Example live stream URLs let liveStreams = [ "http://aljazeera-ara-apple-live.adaptive.level3.net/apple/aljazeera/arabic/160.m3u8", "http://cdn3.viblast.com/streams/hls/airshow/playlist.m3u8" ] ``` -------------------------------- ### Initialize and Attach YBAVPlayerAdapter in Objective-C Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Provides the Objective-C equivalent for setting up the YBAVPlayerAdapter with an AVPlayer and a Youbora plugin. This is useful for projects with mixed language codebases. ```objectivec // Objective-C equivalent #import - (void)viewDidLoad { [super viewDidLoad]; YBOptions *options = [YBOptions new]; options.accountCode = @"your-account-code"; options.contentResource = @"https://example.com/video.m3u8"; options.contentIsLive = @NO; self.plugin = [[YBPlugin alloc] initWithOptions:options]; NSURL *url = [NSURL URLWithString:options.contentResource]; AVPlayer *player = [AVPlayer playerWithURL:url]; // Attach adapter directly in Objective-C [self.plugin setAdapter:[[YBAVPlayerAdapter alloc] initWithPlayer:player]]; [player play]; } ``` -------------------------------- ### Initialize Youbora Analytics Plugin in Swift Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Initializes the YBPlugin for Youbora analytics in Swift. This involves creating a YBOptions object, configuring essential properties like accountCode and content details, and then instantiating the YBPlugin. ```swift import YouboraLib import YouboraAVPlayerAdapter class VideoPlayer { var plugin: YBPlugin? func setupAnalytics() { // Configure analytics options let options = YBOptions() options.accountCode = "your-account-code" options.contentResource = "https://example.com/video.m3u8" options.contentIsLive = NSNumber(value: false) options.contentTitle = "My Video Title" options.contentDuration = NSNumber(value: 3600) // Duration in seconds // Optional: Configure custom dimensions options.contentCustomDimension1 = "category" options.contentCustomDimension2 = "genre" // Initialize the plugin (do once per session) self.plugin = YBPlugin(options: options) } } ``` -------------------------------- ### Set YBAVPlayerAdapter and AdsAdapter (Swift) Source: https://github.com/npaw/avplayer-adapter-ios/blob/master/README.md This Swift snippet illustrates how to integrate the `YBAVPlayerAdapter` and `YBAVPlayerAdsAdapter` with an existing `YBPlugin`. It shows the transformation process using `YBAVPlayerAdapterSwiftTranformer` and how to remove the ads adapter and clean up resources when necessary. ```swift import YouboraAVPlayerAdapter //Once you have your player and plugin initialized you can set the adapter self.plugin.adapter = YBAVPlayerAdapterSwiftTranformer.transform(from: YBAVPlayerAdapter(player: player)) //If you want to setup the ads adapter self.plugin.adsAdapter = YBAVPlayerAdapterSwiftTranformer.transform(from: YBAVPlayerAdsAdapter(player: player)) //When the ad finishes self.plugin.removeAdsAdapter() // When the view gonna be destroyed you can force stop and clean the adapters in order to make sure you avoid retain cycles self.plugin.fireStop() self.plugin.removeAdapter() self.plugin.removeAdsAdapter() ``` -------------------------------- ### Initialize Youbora Analytics Plugin in Objective-C Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Initializes the YBPlugin for Youbora analytics in Objective-C. Similar to the Swift version, it requires creating and configuring YBOptions before initializing the YBPlugin. ```objectivec #import @interface VideoPlayer () // Assuming VideoPlayer is the class name @property (nonatomic, strong) YBPlugin *plugin; @end @implementation VideoPlayer - (void)setupAnalytics { YBOptions *options = [YBOptions new]; options.accountCode = @"your-account-code"; options.contentResource = @"https://example.com/video.m3u8"; options.contentIsLive = @NO; options.contentTitle = @"My Video Title"; options.contentDuration = @3600; self.plugin = [[YBPlugin alloc] initWithOptions:options]; } @end ``` -------------------------------- ### Swift Cleanup and Memory Management for AVPlayerAdapter Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Demonstrates the proper sequence for cleaning up Youbora plugin and AVPlayerAdapter in Swift to prevent memory leaks. It includes calling `fireStop`, `removeAdapter`, and `removeAdsAdapter` in `viewWillDisappear` and `deinit`. ```swift import UIKit import AVKit import YouboraLib import YouboraAVPlayerAdapter class CleanupExample: UIViewController { var plugin: YBPlugin? var playerViewController: AVPlayerViewController? override func viewDidLoad() { super.viewDidLoad() setupPlayer() } func setupPlayer() { let options = YBOptions() options.accountCode = "your-account-code" options.contentResource = "https://example.com/video.m3u8" self.plugin = YBPlugin(options: options) guard let url = URL(string: options.contentResource ?? "") else { return } let player = AVPlayer(url: url) self.playerViewController = AVPlayerViewController() self.playerViewController?.player = player let adapter = YBAVPlayerAdapter(player: player) self.plugin?.adapter = YBAVPlayerAdapterSwiftTranformer.transform(from: adapter) player.play() } // IMPORTANT: Proper cleanup sequence override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) if isMovingFromParent { // 1. Fire stop to send final analytics plugin?.fireStop() // 2. Remove content adapter plugin?.removeAdapter() // 3. Remove ads adapter if set plugin?.removeAdsAdapter() // This cleanup prevents retain cycles between // the adapter, player, and plugin } } deinit { // Ensure cleanup even if viewWillDisappear wasn't called plugin?.fireStop() plugin?.removeAdapter() plugin?.removeAdsAdapter() } } ``` -------------------------------- ### Change Content Items with AVPlayer Adapter for iOS Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Demonstrates how to handle content changes, such as switching videos in a playlist or replacing the current item, using the AVPlayer adapter. It configures the adapter for playlist support and shows methods for changing content and seeking. ```swift import AVFoundation import YouboraLib import YouboraAVPlayerAdapter class PlaylistManager { var plugin: YBPlugin? var player: AVPlayer? func setupInitialContent() { let options = YBOptions() options.accountCode = "your-account-code" options.contentResource = "https://example.com/video1.m3u8" options.contentIsLive = NSNumber(value: false) self.plugin = YBPlugin(options: options) guard let url = URL(string: options.contentResource ?? "") else { return } self.player = AVPlayer(url: url) let adapter = YBAVPlayerAdapter(player: player!) adapter.supportPlaylists = true // Enable playlist support self.plugin?.adapter = YBAVPlayerAdapterSwiftTranformer.transform(from: adapter) player?.play() } func changeToNextVideo(newUrl: String, isLive: Bool) { // Update options for new content plugin?.options.contentResource = newUrl plugin?.options.contentIsLive = NSNumber(value: isLive) // Replace current item - adapter automatically handles stop/start guard let url = URL(string: newUrl) else { return } player?.replaceCurrentItem(with: AVPlayerItem(url: url)) // Playback will continue with new item tracked as separate view } func seekAndReplay() { // Seek to beginning player?.seek(to: .zero) player?.play() } } ``` -------------------------------- ### Configure YBAVPlayerAdapter Properties in Swift Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Illustrates how to configure various properties of the YBAVPlayerAdapter in Swift to customize playback tracking behavior, including playlist support, join time detection, and error handling. ```swift import YouboraAVPlayerAdapter import AVFoundation class PlaylistPlayer { var plugin: YBPlugin? func setupAdapterWithOptions(player: AVPlayer) { let adapter = YBAVPlayerAdapter(player: player) // Enable playlist support - creates new view for each item change (default: YES) adapter.supportPlaylists = true // Auto-detect join time from playhead position (default: YES) adapter.autoJoinTime = true // Prevent stop events when AVQueuePlayer items end (default: NO) // Set to true for continuous playback scenarios adapter.avoidFireStopOnEndQueueItem = false // Add custom fatal error codes that should trigger fireStop adapter.addFatalErrors(NSMutableArray(array: [-12345, -67890])) self.plugin?.adapter = YBAVPlayerAdapterSwiftTranformer.transform(from: adapter) } func handleQueuePlayer() { // For AVQueuePlayer with continuous playback let queuePlayer = AVQueuePlayer(items: [ AVPlayerItem(url: URL(string: "https://example.com/video1.m3u8")!), AVPlayerItem(url: URL(string: "https://example.com/video2.m3u8")!) ]) let adapter = YBAVPlayerAdapter(player: queuePlayer) adapter.supportPlaylists = true // Track each item as separate view adapter.avoidFireStopOnEndQueueItem = true // Don't fire stop between items self.plugin?.adapter = YBAVPlayerAdapterSwiftTranformer.transform(from: adapter) } } ``` -------------------------------- ### Set YBAVPlayerAdapter and AdsAdapter (Objective-C) Source: https://github.com/npaw/avplayer-adapter-ios/blob/master/README.md This Objective-C code demonstrates setting the `YBAVPlayerAdapter` and `YBAVPlayerAdsAdapter` for the Youbora plugin. It includes methods for setting and removing the ads adapter, as well as for stopping the plugin and cleaning up adapters to prevent memory leaks. ```objectivec #import //Once you have your player and plugin initialized you can set the adapter [self.plugin setAdapter:[[YBAVPlayerAdapter alloc] initWithPlayer:player]]; //If you want to setup the ads adapter [self.plugin setAdsAdapter:[[YBAVPlayerAdsAdapter alloc] initWithPlayer:player]]; //When the ad finishes [self.plugin removeAdsAdapter]; // When the view gonna be destroyed you can force stop and clean the adapters in order to make sure you avoid retain cycles [self.plugin fireStop]; [self.plugin removeAdapter]; [self.plugin removeAdsAdapter]; ``` -------------------------------- ### Set YBAVPlayerStreamrootAdapter (Objective-C) Source: https://github.com/npaw/avplayer-adapter-ios/blob/master/README.md This Objective-C code demonstrates the integration of `YBAVPlayerStreamrootAdapter` with the Youbora plugin. It requires initialization of the player, `dnaClient`, and plugin. The code also shows how to stop the plugin and remove the adapter upon view destruction. ```objectivec #import //Once you have your player, dnaClient and plugin initialized you can set the adapter [self.plugin setAdapter:[[YBAVPlayerStreamrootAdapter alloc] initWithDnaClient:dnaClient andPlayer:player]]; // When the view gonna be destroyed you can force stop and clean the adapters in order to make sure you avoid retain cycles [self.plugin fireStop]; [self.plugin removeAdapter]; ``` -------------------------------- ### Set YBAVPlayerPolynetAdapter (Swift) Source: https://github.com/npaw/avplayer-adapter-ios/blob/master/README.md This Swift snippet shows how to integrate the `YBAVPlayerPolynetAdapter` with the Youbora plugin. It requires the `polynet` object, player, and a `polynetDelegate` to be initialized. The code also includes steps for stopping the plugin and removing the adapter when the view is destroyed. ```swift import YouboraAVPlayerAdapter //Once you have your player, plugin and polynet initialized you can set the adapter self.plugin.adapter = YBAVPlayerAdapterSwiftTranformer.transform(from: YBAVPlayerPolynetAdapter(polyNet: polynet, player: player, andDelegate: polynetDelegate)) // When the view gonna be destroyed you can force stop and clean the adapters in order to make sure you avoid retain cycles self.plugin.fireStop() self.plugin.removeAdapter() ``` -------------------------------- ### Objective-C Cleanup and Memory Management for AVPlayerAdapter Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Provides the Objective-C equivalent for cleaning up Youbora plugin and AVPlayerAdapter to prevent memory leaks. It mirrors the Swift implementation by calling `fireStop`, `removeAdapter`, and `removeAdsAdapter` in `viewWillDisappear` and `dealloc`. ```objectivec // Objective-C cleanup - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; if (self.isMovingFromParentViewController) { [self.plugin fireStop]; [self.plugin removeAdapter]; [self.plugin removeAdsAdapter]; } } - (void)dealloc { [self.plugin fireStop]; [self.plugin removeAdapter]; [self.plugin removeAdsAdapter]; } ``` -------------------------------- ### Set YBAVPlayerStreamrootAdapter (Swift) Source: https://github.com/npaw/avplayer-adapter-ios/blob/master/README.md This Swift code shows how to integrate the `YBAVPlayerStreamrootAdapter` with the Youbora plugin. It requires the player, plugin, and a `dnaClient` to be initialized. The snippet also includes steps for stopping the plugin and removing the adapter when the view is destroyed. ```swift import YouboraAVPlayerAdapter //Once you have your player, plugin and dnaClient initialized you can set the adapter self.plugin.adapter = YBAVPlayerAdapterSwiftTranformer.transform(from: YBAVPlayerStreamrootAdapter(dnaClient: dnaClient, andPlayer: player)) // When the view gonna be destroyed you can force stop and clean the adapters in order to make sure you avoid retain cycles self.plugin.fireStop() self.plugin.removeAdapter() ``` -------------------------------- ### Play Mid-Roll Ad and Handle Completion in Objective-C Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Provides an Objective-C implementation for playing a mid-roll ad. It pauses the content player, sets the ad resource, creates an AVPlayer for the ad, attaches the YBAVPlayerAdsAdapter, and registers for ad completion notifications to resume content playback. ```objectivec // Objective-C ads adapter setup - (void)playMidRollAdWithUrl:(NSString *)adUrl { [self.contentPlayer pause]; self.plugin.options.adResource = adUrl; NSURL *url = [NSURL URLWithString:adUrl]; self.adsPlayer = [AVPlayer playerWithURL:url]; // Attach ads adapter [self.plugin setAdsAdapter:[[YBAVPlayerAdsAdapter alloc] initWithPlayer:self.adsPlayer]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(adDidFinish) name:AVPlayerItemDidPlayToEndTimeNotification object:self.adsPlayer.currentItem]; [self.adsPlayer play]; } - (void)adDidFinish { [self.plugin removeAdsAdapter]; [self.contentPlayer play]; } ``` -------------------------------- ### Play Mid-Roll Ad and Handle Completion in Swift Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Handles the playback of a mid-roll ad by pausing content, configuring ad resources, creating and presenting an ads player, and attaching the YBAVPlayerAdsAdapter. It also sets up notification observers for ad completion to resume content playback. ```swift func playMidRollAd(adUrl: String) { // Pause content contentPlayer?.pause() // Configure ad resource in options plugin?.options.adResource = adUrl // Create ads player guard let url = URL(string: adUrl) else { return } self.adsPlayer = AVPlayer(url: url) // Setup ads player view self.adsPlayerViewController = AVPlayerViewController() self.adsPlayerViewController?.player = adsPlayer addChild(adsPlayerViewController!) view.addSubview(adsPlayerViewController!.view) adsPlayerViewController!.view.frame = view.bounds // Create and attach ads adapter let adsAdapter = YBAVPlayerAdsAdapter(player: adsPlayer!) self.plugin?.adsAdapter = YBAVPlayerAdapterSwiftTranformer.transform(from: adsAdapter) // Listen for ad completion NotificationCenter.default.addObserver( self, selector: #selector(adDidFinish), name: .AVPlayerItemDidPlayToEndTime, object: adsPlayer?.currentItem ) // Start ad playback adsPlayer?.play() } @objc func adDidFinish() { // Clean up ads player adsPlayerViewController?.view.removeFromSuperview() adsPlayerViewController?.removeFromParent() adsPlayerViewController = nil // Remove ads adapter plugin?.removeAdsAdapter() // Resume content playback contentPlayer?.play() } ``` -------------------------------- ### Implement Error Handling with AVPlayer Adapter for iOS Source: https://context7.com/npaw/avplayer-adapter-ios/llms.txt Details how to configure custom fatal error codes and handle playback errors within the AVPlayer adapter. It lists default fatal error codes handled by the adapter and shows how to add custom ones. ```swift import AVFoundation import YouboraLib import YouboraAVPlayerAdapter class ErrorHandlingPlayer { var plugin: YBPlugin? func setupWithErrorHandling() { let options = YBOptions() options.accountCode = "your-account-code" options.contentResource = "https://example.com/video.m3u8" self.plugin = YBPlugin(options: options) guard let url = URL(string: options.contentResource ?? "") else { return } let player = AVPlayer(url: url) let adapter = YBAVPlayerAdapter(player: player) // Default fatal error codes handled by adapter: // -1100: URLErrorTimedOut // -11853: AVErrorMediaServicesWereReset // -1005: URLErrorNetworkConnectionLost // -11819: AVErrorContentIsUnavailable // -11800: AVErrorUnknown // -1008: URLErrorResourceUnavailable // Add custom fatal error codes for your application adapter.addFatalErrors(NSMutableArray(array: [ -12345, // Custom error code 1 -67890 // Custom error code 2 ])) self.plugin?.adapter = YBAVPlayerAdapterSwiftTranformer.transform(from: adapter) player.play() } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.