### Initialize Brightcove Player Setup Method (Objective-C) Source: https://sdks.support.brightcove.com/ios/basics/step-step-simple-video-app-using-objective-c Defines the initialization method for the ViewController, which calls a `setup` function. This setup function is responsible for creating and configuring the Brightcove playback controller and playback service. ```objective-c @implementation ViewController #pragma mark Setup Methods - (instancetype)initWithCoder:(NSCoder *)coder { self = [super initWithCoder:coder]; if (self) { [self setup]; } return self; } ``` -------------------------------- ### Initialize ViewController with Setup Source: https://sdks.support.brightcove.com/ios/basics/step-step-simple-video-app-using-objective-c Defines an initializer for the ViewController that calls a setup method. This pattern ensures that necessary player components are initialized upon object creation. It handles the `initWithCoder` method for NIB-based initialization. ```objective-c #import "ViewController.h" @implementation ViewController #pragma mark Setup Methods - (instancetype)initWithCoder:(NSCoder *)coder { self = [super initWithCoder:coder]; if (self) { [self setup]; } return self; } @end ``` -------------------------------- ### Install Brightcove-Player-Core with CocoaPods (Dynamic Framework) Source: https://sdks.support.brightcove.com/ios/reference/sdk/index This example shows how to install the Brightcove Player SDK Core module as a dynamic framework using CocoaPods. By appending '/Framework' to the pod name, you specify the dynamic library installation. This requires the BrightcoveSpecs repository source in your Podfile and targets iOS 12.0 or later. ```ruby source 'https://github.com/CocoaPods/Specs' source 'https://github.com/brightcove/BrightcoveSpecs.git' platform :ios, '12.0' use_frameworks! target 'MyVideoPlayer' do pod 'Brightcove-Player-Core/Framework' end ``` -------------------------------- ### Setup Video Playback with FreeWheel Ads using Brightcove SDK (Swift) Source: https://sdks.support.brightcove.com/ios/reference/plugins/freewheel/index This code snippet demonstrates how to set up video playback using the Brightcove Player SDK for iOS, integrating FreeWheel for ad serving. It covers initializing the ad manager, creating a playback controller with ad context policy, and playing a video. ```swift var adManager: FWAdManager? @IBOutlet weak var videoContainerView: UIView! func setup() { let policyKey = "" let accountId = "" let videoId = "" adManager = newAdManager() adManager?.setNetworkId(90750) let sdkManager = BCOVPlayerSDKManager.sharedManager() guard let playbackController = sdkManager.createFWPlaybackController(adContextPolicy: adContextPolicy(), viewStrategy: nil) else { return } view.addSubview(playbackController.view) let playbackService = BCOVPlaybackService(withAccountId: accountId, policyKey: policyKey) let configuration = [ BCOVPlaybackService.ConfigurationKeyAssetID: videoId ] playbackService.findVideo(withConfiguration: configuration, queryParameters: nil) { (video: BCOVVideo?, jsonResponse: Any?, error: Error?) in if let video { playbackController.setVideos([video]) playbackController.play() } } } func adContextPolicy() -> BCOVFWSessionProviderAdContextPolicy { return { [weak self] (video: BCOVVideo?, source: BCOVSource?, videoDuration: TimeInterval) in guard let self, let adManager = self.adManager, let adContext = adManager.newContext() else { return nil } let adRequestConfig = FWRequestConfiguration(serverURL: "http://demo.v.fwmrm.net", playerProfile: "", playerDimensions: videoContainerView.frame.size) adRequestConfig.siteSectionConfiguration = FWSiteSectionConfiguration(siteSectionId: "", idType: .custom) adRequestConfig.videoAssetConfiguration = FWVideoAssetConfiguration(videoAssetId: "", idType: .custom, duration: videoDuration, durationType: .exact, autoPlayType: .attended) adContext.setVideoDisplayBase(videoContainerView) adRequestConfig.add(FWTemporalSlotConfiguration(customId: "preroll", adUnit: FWAdUnitPreroll, timePosition: 0.0)) adRequestConfig.add(FWTemporalSlotConfiguration(customId: "midroll", adUnit: FWAdUnitPreroll, timePosition: videoDuration / 2)) adRequestConfig.add(FWTemporalSlotConfiguration(customId: "postroll", adUnit: FWAdUnitPostroll, timePosition: 0.0)) let bcovAdContext = BCOVFWContext(adContext: adContext, requestConfiguration: adRequestConfig) return bcovAdContext } } ``` -------------------------------- ### Setup Brightcove Player Source: https://sdks.support.brightcove.com/ios/basics/step-step-simple-video-app-using-objective-c Configures the Brightcove playback controller and service. This method initializes the `BCOVPlayerSDKManager`, sets up analytics (optional), configures delegate, auto-advance, and auto-play features, and initializes the `BCOVPlaybackService` with account and policy keys. ```objective-c - (void)setup { _playbackController = [BCOVPlayerSDKManager.sharedManager createPlaybackController]; _playbackController.analytics.account = kViewControllerAccountID; // Optional _playbackController.delegate = self; _playbackController.autoAdvance = YES; _playbackController.autoPlay = YES; _playbackService = [[BCOVPlaybackService alloc] initWithAccountId:kViewControllerAccountID policyKey:kViewControllerPlaybackServicePolicyKey]; } ``` -------------------------------- ### Install Brightcove iOS SDK using CocoaPods Source: https://sdks.support.brightcove.com/ios/basics/step-step-simple-video-app-using-objective-c This command initiates the download and integration of the specified SDK dependencies into your Xcode project. After running 'pod install', always open the .xcworkspace file instead of the .xcodeproj file for subsequent development. ```bash pod install ``` -------------------------------- ### Install Brightcove-Player-Core with CocoaPods (XCFramework) Source: https://sdks.support.brightcove.com/ios/reference/sdk/index This example demonstrates how to add the Brightcove Player SDK Core module to an iOS project using CocoaPods, specifically for XCFramework installation. Ensure you have CocoaPods installed and have added the BrightcoveSpecs repository source to your Podfile. Deployment is supported on iOS 12.0 and above. ```ruby source 'https://github.com/CocoaPods/Specs' source 'https://github.com/brightcove/BrightcoveSpecs.git' platform :ios, '12.0' use_frameworks! target 'MyVideoPlayer' do pod 'Brightcove-Player-Core' end ``` -------------------------------- ### Install Brightcove SSAI and Open Measurement SDKs via CocoaPods Source: https://sdks.support.brightcove.com/ios/reference/plugins/ssai/index These code snippets show how to add the Brightcove SSAI and Open Measurement SDKs to your iOS project using CocoaPods. Two examples are provided: one for the Universal Framework (Fat Framework) and another for XCFrameworks, catering to different project setup needs. ```ruby pod 'Brightcove-Player-SSAI' pod 'Brightcove-Player-OpenMeasurement' ``` ```ruby pod 'Brightcove-Player-SSAI/XCFramework' pod 'Brightcove-Player-OpenMeasurement' ``` -------------------------------- ### Create and Install Custom BCOVPUIControlLayout (Swift) Source: https://sdks.support.brightcove.com/ios/reference/sdk/index Illustrates the final step of creating a `BCOVPUIControlLayout` object using the defined standard and compact layouts, and then assigning this custom layout to the player's control view. ```swift let customLayout = BCOVPUIControlLayout.init(standardControls: standardLayoutLines, compactControls: compactLayoutLines) playerView?.controlsView.layout = customLayout ``` -------------------------------- ### Initialize BCOVBasicSessionProvider with Options (Swift) Source: https://sdks.support.brightcove.com/ios/reference/sdk/Classes/BCOVBasicSessionProvider Initializes a BCOVBasicSessionProvider with specified options. This method is crucial for configuring the provider with custom settings before it starts yielding playback sessions. ```swift - (nonnull instancetype)initWithOptions:(BCOVBasicSessionProviderOptions *_Nullable)_options_ ``` -------------------------------- ### CocoaPods Podfile Example for Brightcove Google Cast Plugin Source: https://sdks.support.brightcove.com/ios/reference/plugins/googlecast/index An example of a CocoaPods Podfile demonstrating how to include the Brightcove-Player-GoogleCast pod in an iOS project. This setup ensures the correct version of the GoogleCast SDK is automatically incorporated. ```ruby source 'https://github.com/CocoaPods/Specs' source 'https://github.com/brightcove/BrightcoveSpecs.git' platform :ios, '14.0' use_frameworks! target 'ExampleApp' do pod 'Brightcove-Player-GoogleCast' end ``` -------------------------------- ### Configure Player View and Start Playback (Objective-C) Source: https://sdks.support.brightcove.com/ios/basics/step-step-simple-video-app-using-objective-c Configures the player view, associates it with the playback controller, and initiates video playback. This involves creating an array of video sources, setting up the player view using Auto Layout, and adding videos to the playback queue. ```objective-c - (void)viewDidLoad { [super viewDidLoad]; // create an array of videos NSArray *videos = @[ [self videoWithURL:[NSURL URLWithString:@"https://solutions.brightcove.com/bcls/assets/videos/Great_Horned_Owl.mp4"]], [self videoWithURL:[NSURL URLWithString:@"https://solutions.brightcove.com/bcls/assets/videos/Great_Blue_Heron.mp4"]] ]; // Set up our player view. Create with a standard VOD layout. BCOVPUIPlayerView *playerView = [[BCOVPUIPlayerView alloc] initWithPlaybackController:self.playbackController options:nil controlsView:[BCOVPUIBasicControlView basicControlViewWithVODLayout] ]; [_videoContainer addSubview:playerView]; playerView.translatesAutoresizingMaskIntoConstraints = NO; [NSLayoutConstraint activateConstraints:@[ [playerView.topAnchor constraintEqualToAnchor:_videoContainer.topAnchor], [playerView.rightAnchor constraintEqualToAnchor:_videoContainer.rightAnchor], [playerView.leftAnchor constraintEqualToAnchor:_videoContainer.leftAnchor], [playerView.bottomAnchor constraintEqualToAnchor:_videoContainer.bottomAnchor], ]]; _playerView = playerView; // Associate the playerView with the playback controller. _playerView.playbackController = _playbackController; // add the video array to the controller's playback queue [self.playbackController setVideos:videos]; // play the first video [self.playbackController play]; } ``` -------------------------------- ### Install Brightcove Player SDK for iOS - Manual Framework Source: https://sdks.support.brightcove.com/ios/reference/sdk/index Instructions for manually adding the Brightcove Player SDK framework to an iOS project. This involves downloading the framework, adding it to the project, and configuring build settings and embedded content. It also details steps for dynamic and universal frameworks, including script phases for stripping unnecessary architectures. ```bash bash ${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/BrightcovePlayerSDK.framework/strip-frameworks.sh ``` -------------------------------- ### CocoaPods Installation for Brightcove SSAI iOS SDK Source: https://sdks.support.brightcove.com/ios/reference/plugins/ssai/index Integrates the Brightcove SSAI plugin into your iOS project using CocoaPods. Ensure you have the BrightcoveSpecs repository configured as a source. This example targets iOS 12.0 and includes the dynamic library framework. ```ruby source 'https://github.com/brightcove/BrightcoveSpecs.git' use_frameworks! platform :ios, '12.0' target 'MyVideoPlayer' do pod 'Brightcove-Player-SSAI' end ``` -------------------------------- ### CocoaPods Installation for Pulse Plugin (iOS) Source: https://sdks.support.brightcove.com/ios/reference/plugins/pulse/index Example of how to add the Pulse Plugin for the Brightcove Player SDK to an iOS project using CocoaPods. This requires specifying the BrightcoveSpecs repository and the 'Brightcove-Player-Pulse' pod. ```ruby source 'https://github.com/CocoaPods/Specs' source 'https://github.com/brightcove/BrightcoveSpecs.git' platform :ios, '12.0' use_frameworks! target 'MyApp' do pod 'Brightcove-Player-Pulse' end ``` -------------------------------- ### BCOVInteractivityHandler Initialization Source: https://sdks.support.brightcove.com/ios/reference/sdk/Classes/BCOVInteractivityHandler Initializes a new instance of BCOVInteractivityHandler with necessary playback and project details. ```APIDOC ## BCOVInteractivityHandler Initialization ### Description Initializes and returns a new `BCOVInteractivityHandler` object, configuring it with the provided account ID, project ID, container view, and playback controller. ### Method - (instancetype)initWithAccountId:(NSString *)_accountId_ projectId:(NSString *)_projectId_ containerView:(UIView *)_containerView_ playbackController:(id)_playbackController_ ### Endpoint N/A (Initialization method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```objc BCOVInteractivityHandler *interactivityHandler = [[BCOVInteractivityHandler alloc] initWithAccountId:@"YOUR_ACCOUNT_ID" projectId:@"YOUR_PROJECT_ID" containerView:self.playerView playbackController:self.playerViewController]; ``` ### Response #### Success Response (200) N/A (Initialization returns an instance) #### Response Example N/A ``` -------------------------------- ### BCOVVideo Initializers Source: https://sdks.support.brightcove.com/ios/reference/sdk/Classes/BCOVVideo Methods for creating new BCOVVideo instances with different configurations. ```APIDOC ## BCOVVideo Initializers This section details the various methods available for initializing `BCOVVideo` objects. ### `– initWithSources:cuePoints:properties:` Returns a new video with the specified sources, cue points, and properties. **Method:** `-[nonnull instancetype] initWithSources:(NSArray *_Nullable)_sources_ cuePoints:(BCOVCuePointCollection *_Nullable)_cuePoints_ properties:(NSDictionary *_Nullable)_properties_` **Parameters:** * `_sources_` (NSArray * _Nullable): An array of BCOVSource objects. * `_cuePoints_` (BCOVCuePointCollection * _Nullable): A BCOVCuePointCollection object. * `_properties_` (NSDictionary * _Nullable): A dictionary of properties. ### `– initWithSource:cuePoints:properties:` Returns a new video with a single source, as well as the specified cue points and properties. **Method:** `-[nonnull instancetype] initWithSource:(BCOVSource *_Nullable)_source_ cuePoints:(BCOVCuePointCollection *_Nullable)_cuePoints_ properties:(NSDictionary *_Nullable)_properties_` **Parameters:** * `_source_` (BCOVSource * _Nullable): A BCOVSource object. * `_cuePoints_` (BCOVCuePointCollection * _Nullable): A BCOVCuePointCollection object. * `_properties_` (NSDictionary * _Nullable): A dictionary of properties. ### `– initWithErrorCode:errorSubCode:errorMessage:properties:` Returns a new video with error information attributes. Returns `false` if `errorCode`, `errorSubCode` and `errorMessage` are all nil; otherwise, if any of those properties have a value, it will return `true`. **Method:** `-[nonnull instancetype] initWithErrorCode:(NSString *_Nullable)_errorCode_ errorSubCode:(NSString *_Nullable)_errorSubCode_ errorMessage:(NSString *_Nullable)_errorMessage_ properties:(NSDictionary *_Nullable)_properties_` **Parameters:** * `_errorCode_` (NSString * _Nullable): The error code. * `_errorSubCode_` (NSString * _Nullable): The error sub-code. * `_errorMessage_` (NSString * _Nullable): The error message. * `_properties_` (NSDictionary * _Nullable): A dictionary of properties. ### `– init` Initializes a new, empty BCOVVideo object. **Method:** `-[nonnull instancetype] init` ### `+ new` Creates and returns a new, empty BCOVVideo object. **Method:** `+ (nonnull instancetype)new` ``` -------------------------------- ### Prevent Preroll Ad Repetition in Swift Source: https://sdks.support.brightcove.com/ios/reference/plugins/ssai/index Illustrates how to prevent a preroll ad from playing again by checking its start time in `willPresentInterstitialTimeRange:` and conditionally seeking past it. A flag `didPlayPreroll` is used to track if the preroll has already played. ```swift func playerViewController(_ playerViewController: AVPlayerViewController, willPresent interstitial: AVInterstitialTimeRange) { if CMTimeCompare(interstitial.timeRange.start, .zero) == 0 && didPlayPreroll { playerViewController.player?.seek(to: interstitial.timeRange.duration) } } func playerViewController(_ playerViewController: AVPlayerViewController, didPresent interstitial: AVInterstitialTimeRange) { if CMTimeCompare(interstitial.timeRange.start, .zero) == 0 { didPlayPreroll = true } } ``` -------------------------------- ### PlayerUI Setup for Brightcove DAI (Objective-C) Source: https://sdks.support.brightcove.com/ios/reference/plugins/dai/index This snippet shows how to integrate the Built-in PlayerUI with the Brightcove DAI plugin. It involves declaring a BCOVPUIPlayerView property, creating a basic control view, initializing the player view, and adding it to the main video view. ```Objective-C // Declare PlayerUI's player view property @property (nonatomic) BCOVPUIPlayerView *playerView; // Create and configure Control View. BCOVPUIBasicControlView *controlView = [BCOVPUIBasicControlView basicControlViewWithVODLayout]; // Create the player view with a nil playback controller. self.playerView = [[BCOVPUIPlayerView alloc] initWithPlaybackController:nil options:nil controlsView:controlView]; // Add BCOVPUIPlayerView to your video view. [self.videoView addSubview:self.playerView]; ``` -------------------------------- ### Set up Brightcove Player Controller (Objective-C) Source: https://sdks.support.brightcove.com/ios/basics/step-step-simple-video-app-using-objective-c Initializes the BCOVPlaybackController, sets the analytics account ID, assigns a delegate, and enables auto-advance and auto-play features. This method is typically called when the application loads. ```objective-c - (void)setup { _playbackController = [BCOVPlayerSDKManager.sharedManager createPlaybackController]; _playbackController.analytics.account = kViewControllerAccountID; _playbackController.delegate = self; _playbackController.autoAdvance = YES; _playbackController.autoPlay = YES; } ``` -------------------------------- ### Quick Start: Play Video with Brightcove Player SDK for iOS Source: https://sdks.support.brightcove.com/ios/reference/sdk/index A basic implementation to play a video using the Brightcove Player SDK for iOS. This involves initializing the SDK manager, creating a playback controller, setting up a playback service with account details, finding a video by its ID, and then playing the video. It also highlights the importance of maintaining a strong reference to the playback controller. ```swift // ** Customize these values with your own account information ** let kAccountId = "..." let kPolicyKey = "..." let kVideoId = "..." let sdkManager = BCOVPlayerSDKManager.sharedManager() let playbackController = sdkManager.createPlaybackController() self.playbackController = playbackController // store this to a strong property view.addSubview(playbackController.view) let playbackService = BCOVPlaybackService(withAccountId: kAccountId, policyKey: kPolicyKey) let configuration = [ BCOVPlaybackService.ConfigurationKeyAssetID: kVideoId ] playbackService.findVideo(withConfiguration: configuration, queryParameters: nil) { (video: BCOVVideo?, jsonResponse: Any?, error: Error?) in if let video { self.playbackController?.setVideos([video]) self.playbackController?.play() } } ``` -------------------------------- ### Update Video Properties for VOD Ads Source: https://sdks.support.brightcove.com/ios/reference/plugins/dai/index These code examples show how to update a BCOVVideo object with properties required for VOD ad targeting, specifically `kBCOVDAIVideoPropertiesKeySourceId` and `kBCOVDAIVideoPropertiesKeyVideoId`. The Objective-C version uses an update block, while the Swift version uses a closure. ```Objective-C - (BCOVVideo *)updateVideo:(BCOVVideo *)video { return [video update:^(id mutableVideo) { NSDictionary *adProperties = @{ kBCOVDAIVideoPropertiesKeySourceId: kViewControllerGoogleDAISourceId, kBCOVDAIVideoPropertiesKeyVideoId: kViewControllerGoogleDAIVideoId }; NSMutableDictionary *propertiesToUpdate = mutableVideo.properties.mutableCopy; [propertiesToUpdate addEntriesFromDictionary:adProperties]; mutableVideo.properties = propertiesToUpdate; }]; } ``` ```Swift func updateVideo(_ video: BCOVVideo) -> BCOVVideo { return update { (mutableVideo: BCOVMutableVideo?) in guard let mutableVideo = mutableVideo else { return } if var updatedProperties = mutableVideo.properties { updatedProperties[kBCOVDAIVideoPropertiesKeySourceId] = GoogleDAIConfig.SourceID updatedProperties[kBCOVDAIVideoPropertiesKeyVideoId] = GoogleDAIConfig.VideoID mutableVideo.properties = updatedProperties } } } ``` -------------------------------- ### Get All Offline Video Statuses (Objective-C) Source: https://sdks.support.brightcove.com/ios/reference/sdk/Classes/BCOVOfflineVideoManager Retrieves an array containing the status of all current and past video downloads. Each status object provides details such as download state, progress, start time, and any associated errors. Objects in the returned array are copies and can be modified without affecting the download manager. ```Objective-C - (NSArray *)offlineVideoStatus ``` -------------------------------- ### Implement Video Playback Controller in Objective-C Source: https://sdks.support.brightcove.com/ios/basics/step-step-simple-video-app-using-objective-c Provides the complete ViewController implementation in Objective-C for setting up and playing videos using the Brightcove Native SDK. It initializes the playback controller, configures playback settings, sets up the player view, and manages the video queue. Dependencies include the Brightcove Player SDK frameworks. ```Objective-C // // ViewController.m // Simple-Video-Playback // // Copyright © Brightcove. All rights reserved. // #import "ViewController.h" // ** Customize these values with your own account information ** static NSString * const kViewControllerAccountID = @"your account id"; @interface ViewController () @property (nonatomic, strong) id playbackController; @property (nonatomic) BCOVPUIPlayerView *playerView; @property (nonatomic, weak) IBOutlet UIView *videoContainer; @end @implementation ViewController #pragma mark Setup Methods - (instancetype)initWithCoder:(NSCoder *)coder { self = [super initWithCoder:coder]; if (self) { [self setup]; } return self; } - (void)setup { _playbackController = [BCOVPlayerSDKManager.sharedManager createPlaybackController]; _playbackController.analytics.account = kViewControllerAccountID; // optional _playbackController.delegate = self; _playbackController.autoAdvance = YES; _playbackController.autoPlay = YES; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // create an array of videos NSArray *videos = @[ [self videoWithURL:[NSURL URLWithString:@"https://solutions.brightcove.com/bcls/assets/videos/Great_Horned_Owl.mp4"]], [self videoWithURL:[NSURL URLWithString:@"https://solutions.brightcove.com/bcls/assets/videos/Great_Blue_Heron.mp4"]] ]; // Set up our player view. Create with a standard VOD layout. BCOVPUIPlayerView *playerView = [[BCOVPUIPlayerView alloc] initWithPlaybackController:self.playbackController options:nil controlsView:[BCOVPUIBasicControlView basicControlViewWithVODLayout] ]; // add the view as a subview of the main view [_videoContainer addSubview:playerView]; playerView.translatesAutoresizingMaskIntoConstraints = NO; [NSLayoutConstraint activateConstraints:@[ [playerView.topAnchor constraintEqualToAnchor:_videoContainer.topAnchor], [playerView.rightAnchor constraintEqualToAnchor:_videoContainer.rightAnchor], [playerView.leftAnchor constraintEqualToAnchor:_videoContainer.leftAnchor], [playerView.bottomAnchor constraintEqualToAnchor:_videoContainer.bottomAnchor], ]]; _playerView = playerView; // Associate the playerView with the playback controller. _playerView.playbackController = _playbackController; // add the video array to the controller's playback queue [self.playbackController setVideos:videos]; // play the first video [self.playbackController play]; } - (BCOVVideo *)videoWithURL:(NSURL *)url { // set the delivery method for BCOVSources that belong to a video BCOVSource *source = [[BCOVSource alloc] initWithURL:url deliveryMethod:kBCOVSourceDeliveryHLS properties:nil]; return [[BCOVVideo alloc] initWithSource:source cuePoints:[BCOVCuePointCollection collectionWithArray:@[]] properties:@{}]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end ``` -------------------------------- ### CocoaPods Installation for FreeWheel Plugin (XCFramework) Source: https://sdks.support.brightcove.com/ios/reference/plugins/freewheel/index This code snippet shows how to install the FreeWheel Plugin for Brightcove Player SDK as an XCFramework using CocoaPods. It appends the '/XCFramework' subspec to the pod name for installation. ```ruby source 'https://github.com/CocoaPods/Specs' source 'https://github.com/brightcove/BrightcoveSpecs.git' platform :ios, '12.0' use_frameworks! target 'MyVideoPlayer' do pod 'Brightcove-Player-FreeWheel/XCFramework' end ``` -------------------------------- ### Initialize Player Controller and Configure Settings Source: https://sdks.support.brightcove.com/ios/basics/step-step-simple-video-app-using-swift Creates the playback controller using the shared SDK manager and configures playback settings such as delegate assignment, auto-advance, and auto-play. This initialization is required before using the playback controller. Analytics can optionally be enabled. ```swift required init?(coder aDecoder: NSCoder) { playbackController = (sharedSDKManager?.createPlaybackController())! super.init(coder: aDecoder) playbackController.analytics.account = kViewControllerAccountID // Optional playbackController.delegate = self playbackController.isAutoAdvance = true playbackController.isAutoPlay = true } ``` -------------------------------- ### Swift Package Manager Installation for Brightcove Omniture Plugin Source: https://sdks.support.brightcove.com/ios/reference/plugins/omniture/index Instructions for adding the Brightcove Omniture Plugin to your iOS project using Swift Package Manager. This method requires prior setup of the Core XCFramework and linking specific libraries. Ensure Adobe Marketing Cloud and Video Heartbeat are also added. ```shell https://github.com/brightcove/brightcove-player-sdk-ios-omniture.git ``` -------------------------------- ### Retrieve Playlist: Swift and Objective-C Examples Source: https://sdks.support.brightcove.com/ios/resources/code-snippets-using-native-sdk-ios Demonstrates how to retrieve a playlist of videos using the BCOVPlaybackService. It covers initializing the service, making the request, and handling the response, including updating local video lists and titles. Dependencies include the Brightcove SDK classes for playback service and request factories. ```Swift func retrievePlaylist() { refreshControl.beginRefreshing() let playbackServiceRequestFactory = BCOVPlaybackServiceRequestFactory(accountId: kDynamicDeliveryAccountID, policyKey: kDynamicDeliveryPolicyKey) let playbackService = BCOVPlaybackService(requestFactory: playbackServiceRequestFactory) playbackService?.findPlaylist(withConfiguration: configuration, parameters: nil, completion: { [weak self] (playlist: BCOVPlaylist?, jsonResponse: [AnyHashable:Any]?, error: Error?) in guard let strongSelf = self else { return } strongSelf.refreshControl.endRefreshing() if let playlist = playlist { strongSelf.currentVideos = playlist.videos strongSelf.currentPlaylistTitle = playlist.properties["name"] as? String ?? "" strongSelf.currentPlaylistDescription = playlist.properties["description"] as? String ?? "" print("Retrieved playlist containing \(playlist.videos.count) videos") strongSelf.usePlaylist(playlist) } else { print("No playlist for ID \(kDynamicDeliveryPlaylistRefID) was found.") } }) } ``` ```Objective-C - (void)retrievePlaylist { [self.refreshControl beginRefreshing]; // Retrieve a playlist through the BCOVPlaybackService BCOVPlaybackServiceRequestFactory *playbackServiceRequestFactory = [[BCOVPlaybackServiceRequestFactory alloc] initWithAccountId:kDynamicDeliveryAccountID policyKey:kDynamicDeliveryPolicyKey]; BCOVPlaybackService *playbackService = [[BCOVPlaybackService alloc] initWithRequestFactory:playbackServiceRequestFactory]; [playbackService findPlaylistWithConfiguration:configuration parameters:nil completion:^(BCOVPlaylist *playlist, NSDictionary *jsonResponse, NSError *error) { [self.refreshControl endRefreshing]; NSLog(@"JSON Response:\n%@", jsonResponse); if (playlist) { self.currentVideos = playlist.videos.mutableCopy; self.currentPlaylistTitle = playlist.properties[@"name"]; self.currentPlaylistDescription = playlist.properties[@"description"]; NSLog(@"Retrieved playlist containing %d videos", (int)self.currentVideos.count); [self usePlaylist:self.currentVideos]; } else { NSLog(@"No playlist for ID %@ was found.", kDynamicDeliveryPlaylistRefID); } }]; } ``` -------------------------------- ### BCOVSource Initialization Methods (Objective-C) Source: https://sdks.support.brightcove.com/ios/reference/sdk/Classes/BCOVSource Provides the Objective-C signatures for initializing a BCOVSource object. These methods allow creating a source with a URL, or with a URL, delivery method, and properties. ```objectivec - (nonnull instancetype)initWithURL:(NSURL *_Nullable)_url_ ``` ```objectivec - (nonnull instancetype)initWithURL:(NSURL *_Nullable)_url_ deliveryMethod:(NSString *_Nullable)_deliveryMethod_ properties:(NSDictionary *_Nullable)_properties_ ``` ```objectivec - (nonnull instancetype)init ``` -------------------------------- ### Display Custom Ad UI with Swift Source: https://sdks.support.brightcove.com/ios/reference/plugins/freewheel/index This example shows how to implement custom UI elements during ad playback using the BCOVPlaybackControllerDelegate methods. It specifically uses `didEnterAdSequence` to display an ad UI and `didExitAdSequence` to hide it, providing the ad duration for the UI. This requires a custom `displayAdUI` and `hideAdUI` function implementation. ```swift // MARK: BCOVPlaybackControllerDelegate func playbackController(_ controller: BCOVPlaybackController, playbackSession session: BCOVPlaybackSession, didEnter ad: BCOVAd) { displayAdUI(withAdDuration: CMTimeGetSeconds(ad.duration)) } func playbackController(_ controller: BCOVPlaybackController, playbackSession session: BCOVPlaybackSession, didExitAdSequence adSequence: BCOVAdSequence) { hideAdUI() } ``` -------------------------------- ### Configure Playback Controller for Seek Without Ads in Swift Source: https://sdks.support.brightcove.com/ios/reference/plugins/ima/index This Swift code demonstrates the setup of a `BCOVPlaybackController` for use with 'Seek Without Ads'. It initializes the IMA playback controller, sets the delegate, and configures properties like `shutter`, `shutterFadeTime`, and `isAutoPlay` when resuming playback to manage ad skipping and visual transitions. ```swift let sdkManager = BCOVPlayerSDKManager.sharedManager() let playbackController = sdkManager.createIMAPlaybackController(with: imaSettings, adsRenderingSettings: adsRenderingSettings, adsRequestPolicy: adsRequestPolicy, adContainer: playerView.contentOverlayView, viewController: self, companionSlots: nil, viewStrategy: nil) playbackController.delegate = self if resumePlayback { // set the shutter fade time to zero to hide the player view immediately. playbackController.shutterFadeTime = 0 playbackController.shutter = true // disable autoPlay when resuming playback. playbackController.isAutoPlay = false } ``` -------------------------------- ### Declare Constants and Initialize Player Components Source: https://sdks.support.brightcove.com/ios/basics/step-step-simple-video-app-using-swift Initializes the Brightcove SDK manager, playback service, and playback controller. It also declares the container view for the video player. Dependencies include `BCOVPlayerSDKManager`, `BCOVPlaybackService`, and `BCOVPlaybackController`. ```swift class ViewController: UIViewController, BCOVPlaybackControllerDelegate { let sharedSDKManager = BCOVPlayerSDKManager.shared() let playbackService = BCOVPlaybackService(accountId: kViewControllerAccountID, policyKey: kViewControllerPlaybackServicePolicyKey) let playbackController :BCOVPlaybackController @IBOutlet weak var videoContainerView: UIView! ``` -------------------------------- ### Create and Assign DAI Playback Controller (Objective-C) Source: https://sdks.support.brightcove.com/ios/reference/plugins/dai/index This Objective-C code illustrates the creation of a Digital Ad Insertion (DAI) playback controller using `createDAIPlaybackControllerWithSettings`. It specifies the `contentOverlayView` from the player as the `adContainer` and then assigns the created controller to the player view. This setup is crucial for displaying ads with player UI controls and ad markers. ```objective-c // Create the playback controller. id controller = [manager createDAIPlaybackControllerWithSettings:imaSettings adsRenderingSettings:adsRenderingSettings adsRequestPolicy:adsRequestPolicy adContainer:playerView.contentOverlayView viewController:self companionSlots:nil viewStrategy:nil]; controller.delegate = self; // Assign new playback controller to the player view. // This associates the playerController's session with the PlayerUI. // You can keep this player view around and assign new // playback controllers to it as they are created. self.playerView.playbackController = self.playbackController; ``` -------------------------------- ### Initialize BCOVPlaybackService with Account and Policy Key (Objective-C) Source: https://sdks.support.brightcove.com/ios/reference/sdk/Classes/BCOVPlaybackService Initializes an instance of BCOVPlaybackService using an account ID and a policy key. This is a common way to set up the service for playback. The `initWithAccountId:policyKey:` method is declared in `BrightcovePlayerSDK-Swift.h`. ```Objective-C - (nonnull instancetype)initWithAccountId:(NSString *_Nonnull)_accountId_ policyKey:(NSString *_Nullable)_policyKey_ ``` -------------------------------- ### Brightcove Player SDK: Setup and Playback in Swift Source: https://sdks.support.brightcove.com/ios/basics/ios-working-media-content This Swift code demonstrates how to initialize and configure the Brightcove Player SDK for iOS. It includes setting up the playback controller, configuring analytics, and loading an array of video URLs for playback within a UIView. ```swift import UIKit import BrightcovePlayerSDK let kViewControllerAccountID = "your account id" // For Brightcove registration class ViewController: UIViewController, BCOVPlaybackControllerDelegate { let sharedSDKManager = BCOVPlayerSDKManager.shared() let playbackController :BCOVPlaybackController @IBOutlet weak var videoContainerView: UIView! required init?(coder aDecoder: NSCoder) { // Create the Brightcove playback controller playbackController = (sharedSDKManager?.createPlaybackController())! super.init(coder: aDecoder) // Register your app with Brightcove playbackController.analytics.account = kViewControllerAccountID // Configure the player playbackController.delegate = self playbackController.isAutoAdvance = true playbackController.isAutoPlay = true } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // Create an array of videos var videoArray = [AnyObject]() videoArray = [videoWithURL(url: NSURL(string: "https://solutions.brightcove.com/bcls/assets/videos/Great_Horned_Owl.mp4")!), videoWithURL(url: NSURL(string: "https://solutions.brightcove.com/bcls/assets/videos/Great_Blue_Heron.mp4")!)] // Set up the player view with a standard VOD layout. guard let playerView = BCOVPUIPlayerView(playbackController: self.playbackController, options: nil, controlsView: BCOVPUIBasicControlView.withVODLayout()) else { return } // Install in the container view and match its size. self.videoContainerView.addSubview(playerView) playerView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ playerView.topAnchor.constraint(equalTo: self.videoContainerView.topAnchor), playerView.rightAnchor.constraint(equalTo: self.videoContainerView.rightAnchor), playerView.leftAnchor.constraint(equalTo: self.videoContainerView.leftAnchor), playerView.bottomAnchor.constraint(equalTo: self.videoContainerView.bottomAnchor) ]) // Associate the playerView with the playback controller. playerView.playbackController = playbackController // Load the video array into the player and start video playback playbackController.setVideos(videoArray as NSArray) playbackController.play(); } func videoWithURL(url: NSURL) -> BCOVVideo { // Set the delivery method for BCOVSources that belong to a video let source:BCOVSource = BCOVSource(url: url as URL, deliveryMethod: kBCOVSourceDeliveryHLS, properties: nil) let video = BCOVVideo.init(source: source, cuePoints: BCOVCuePointCollection.init(array: []), properties: [NSObject:AnyObject]()) return video! } } ``` -------------------------------- ### CocoaPods Installation for Brightcove Omniture Plugin (Framework) Source: https://sdks.support.brightcove.com/ios/reference/plugins/omniture/index This code snippet demonstrates installing the Brightcove Omniture plugin as a framework using CocoaPods. Append '/Framework' to the pod name to use this installation method. Verify your Podfile configuration. ```ruby source 'https://github.com/CocoaPods/Specs' source 'https://github.com/brightcove/BrightcoveSpecs.git' platform :ios, '12.0' use_frameworks! target 'MyOmniturePlayer' do pod 'Brightcove-Player-Omniture/Framework' end ``` -------------------------------- ### Initialize Brightcove SSAI Playback Controller Source: https://sdks.support.brightcove.com/ios/reference/plugins/ssai/index This code snippet demonstrates the essential steps to initialize and configure the Brightcove SSAI playback controller. It involves creating an ad component display container, obtaining the shared SDK manager, creating the SSAI playback controller, adding the display container, setting up the video view, and fetching video playback data using the BCOVPlaybackService. The video data is then loaded into the controller, and playback is initiated. ```swift let displayContainer = BCOVSSAIAdComponentDisplayContainer(companionSlots: []) let sdkManager = BCOVPlayerSDKManager.sharedManager() let playbackController = sdkManager.createSSAIPlaybackController() playbackController.add(displayContainer) videoView.addSubview(playerView) let policyKey = "" let accountID = "" let videoID = "" let playbackService = BCOVPlaybackService(withAccountId: accountID, policyKey: policyKey) let configuration = [ BCOVPlaybackService.ConfigurationKeyAssetID: videoID ] let queryParameters = [ BCOVPlaybackService.ParamaterKeyAdConfigId: "" ] playbackService.findVideo(withConfiguration: configuration, queryParameters: queryParameters) { (video: BCOVVideo?, jsonResponse: Any?, error: Error?) in if let video { playbackController.setVideos([video]) playbackController.play() } } ``` -------------------------------- ### Install Brightcove SDK using CocoaPods Terminal Commands Source: https://sdks.support.brightcove.com/ios/framework/swiftui-development These terminal commands are used to install or update the Brightcove Player SDK dependencies in your Xcode project after creating a Podfile. Navigate to your project folder in the terminal and execute 'pod install' or 'pod update' as needed. ```bash pod install ``` ```bash pod update ``` -------------------------------- ### Configure Brightcove Player View and Playback in Swift Source: https://sdks.support.brightcove.com/ios/basics/step-step-simple-video-app-using-swift Configures the Brightcove player within the `viewDidLoad` function. It sets up an array of video sources from URLs, creates and configures the player view using Auto Layout, associates it with the playback controller, and initiates video playback. Dependencies include `BCOVPUIPlayerView` and `BCOVPUIBasicControlView`. ```swift override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // Create an array of videos var videoArray = [AnyObject]() videoArray = [videoWithURL(url: NSURL(string: "https://solutions.brightcove.com/bcls/assets/videos/Great_Horned_Owl.mp4")!), videoWithURL(url: NSURL(string: "https://solutions.brightcove.com/bcls/assets/videos/Great_Blue_Heron.mp4")!)] // Set up the player view with a standard VOD layout. guard let playerView = BCOVPUIPlayerView(playbackController: self.playbackController, options: nil, controlsView: BCOVPUIBasicControlView.withVODLayout()) else { return } // Install the container view and match its size. self.videoContainerView.addSubview(playerView) playerView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ playerView.topAnchor.constraint(equalTo: self.videoContainerView.topAnchor), playerView.rightAnchor.constraint(equalTo: self.videoContainerView.rightAnchor), playerView.leftAnchor.constraint(equalTo: self.videoContainerView.leftAnchor), playerView.bottomAnchor.constraint(equalTo: self.videoContainerView.bottomAnchor) ]) // Associate the playerView with the playback controller. playerView.playbackController = playbackController // Load the video array into the player and start video playback playbackController.setVideos(videoArray as NSArray) playbackController.play(); } ``` -------------------------------- ### CocoaPods XCFramework Installation for Brightcove SSAI iOS SDK Source: https://sdks.support.brightcove.com/ios/reference/plugins/ssai/index Installs the Brightcove SSAI plugin for iOS using CocoaPods, specifically targeting the XCFramework distribution. This method appends the '/XCFramework' subspec to the pod. It requires iOS 12.0 or later and uses the BrightcoveSpecs repository. ```ruby source 'https://github.com/brightcove/BrightcoveSpecs.git' use_frameworks! platform :ios, '12.0' target 'MyVideoPlayer' do pod 'Brightcove-Player-SSAI/XCFramework' end ``` -------------------------------- ### Install Google Mobile Ads SDK with CocoaPods for iOS Source: https://sdks.support.brightcove.com/ios/reference/plugins/ima/index This snippet demonstrates how to install the Google Mobile Ads SDK as a separate CocoaPod for use with the Brightcove Native Player SDK on iOS. This is required for AdMob integration as it's no longer bundled with the IMA plugin. ```ruby pod 'Google-Mobile-Ads-SDK' ``` -------------------------------- ### Video and Playlist Request with Auth Token (Swift) Source: https://sdks.support.brightcove.com/ios/reference/sdk/index Demonstrates how to make video and playlist requests using the BCOVPlaybackService with an authentication token. Requires BCOVPlaybackService.ConfigurationKeyAuthToken. Handles video and playlist responses, returning video/playlist objects or errors. ```swift // Video Request let configuration = [ BCOVPlaybackService.ConfigurationKeyAssetID: videoID, BCOVPlaybackService.ConfigurationKeyAuthToken: authToken ] playbackService.findVideo(withConfiguration: configuration, queryParameters: nil) { (video: BCOVVideo?, jsonResponse: Any?, error: Error?) in ... } // Playlist Request let configuration = [ BCOVPlaybackService.ConfigurationKeyAssetID: playlistID, BCOVPlaybackService.ConfigurationKeyAuthToken: authToken ] playbackService.findPlaylist(withConfiguration: configuration, queryParameters: nil) { (playlist: BCOVPlaylist?, jsonResponse: Any?, error: Error?) in ... } ``` -------------------------------- ### Install DAI Plugin using CocoaPods for iOS Source: https://sdks.support.brightcove.com/ios/reference/plugins/dai/index This snippet shows how to add the DAI Plugin for Brightcove Player SDK to an iOS project using CocoaPods. It specifies the repository sources and platform settings, ensuring the correct versions of the Brightcove Player DAI pod and its dependencies are installed. ```bash source 'https://github.com/CocoaPods/Specs' source 'https://github.com/brightcove/BrightcoveSpecs.git' platform :ios, ‘14.0’ use_frameworks! target ‘MyDAIPlayer’ do pod ‘Brightcove-Player-DAI’ end ``` -------------------------------- ### BCOVFPSBrightcoveAuthProxy Initializers Source: https://sdks.support.brightcove.com/ios/reference/sdk/Classes/BCOVFPSBrightcoveAuthProxy Methods for initializing the BCOVFPSBrightcoveAuthProxy instance. ```APIDOC ## Initializers ### `initWithPublisherId:applicationId:` * **Method:** `- (nonnull instancetype)initWithPublisherId:(NSString *_Nullable)_pubId_ applicationId:(NSString *_Nullable)_appId_` * **Description:** Returns an initialized proxy with the specified publisher and application IDs. ### `init` * **Method:** `- (nonnull instancetype)init` ### `new` * **Method:** `+ (nonnull instancetype)new` ``` -------------------------------- ### Basic AVAudioSession Configuration for Playback in iOS Source: https://sdks.support.brightcove.com/ios/reference/sdk/index Configures the shared `AVAudioSession` to `.playback` category, which is a common setup for audio playback applications. This code snippet demonstrates a basic `try-catch` block to handle potential errors during the configuration process. It's often placed in the `application:didFinishLaunchingWithOptions:` method of your AppDelegate. ```swift var categoryError :NSError? var success: Bool do { // see https://developer.apple.com/documentation/avfoundation/avaudiosessioncategoryplayback try AVAudioSession.sharedInstance().setCategory(.playback) success = true } catch let error as NSError { categoryError = error success = false } if !success { // Handle error } ``` -------------------------------- ### Update Brightcove iOS SDK using CocoaPods Source: https://sdks.support.brightcove.com/ios/basics/step-step-simple-video-app-using-objective-c If the latest version of the Brightcove Native SDK is not installed, this command can be used to update dependencies to their newest compatible versions. Similar to 'pod install', subsequent project access should be through the .xcworkspace file. ```bash pod update ``` -------------------------------- ### BCOVFWContext Initialization (Objective-C) Source: https://sdks.support.brightcove.com/ios/reference/plugins/freewheel/Classes/BCOVFWContext Provides the Objective-C methods for initializing the `BCOVFWContext` class. This includes the standard `init` method and a custom initializer that takes `FWContext` and `FWRequestConfiguration` objects. ```Objective-C - (BCOVFWContext *)initWithAdContext:(id)_adContext_ requestConfiguration:(FWRequestConfiguration *)_adRequestConfig_ ``` ```Objective-C - (id)init ``` -------------------------------- ### BCOVFWSessionProvider Class Reference Source: https://sdks.support.brightcove.com/ios/reference/plugins/freewheel/Classes/BCOVFWSessionProvider Details about the BCOVFWSessionProvider class, its inheritance, conformance, and declaration. ```APIDOC ## BCOVFWSessionProvider Class Reference ### Description Session provider implementation that delivers playback sessions with support for FreeWheel ads. Instances of this class should not be created directly by clients of the Brightcove Player SDK for iOS; instead use the `[BCOVPlayerSDKManager createFWSessionProviderWithAdContextPolicy:upstreamSessionProvider:options:]` factory method (which is added as a category method). ### Inheritance - **Inherits from**: `NSObject` ### Conformance - **Conforms to**: `BCOVPlaybackSessionProvider` ### Declaration - **Declared in**: `BCOVFWSessionProvider.h` ``` -------------------------------- ### CocoaPods Installation with XCFramework for Pulse Plugin (iOS) Source: https://sdks.support.brightcove.com/ios/reference/plugins/pulse/index Configuration for installing the Pulse Plugin for the Brightcove Player SDK as an XCFramework using CocoaPods. This involves appending '/XCFramework' to the pod name in the Podfile. ```ruby source 'https://github.com/CocoaPods/Specs' source 'https://github.com/brightcove/BrightcoveSpecs.git' platform :ios, '12.0' use_frameworks! target 'MyApp' do pod 'Brightcove-Player-Pulse/XCFramework' end ```