Overview
Video Cloud customers have access to their media data and metadata from Video Cloud Studio. Brightcove Player customers will supply the URL for their media content.
Video Cloud customers
As a Video Cloud customer, you can access your media data stored in Video Cloud Studio. For more information, see the Native Player SDK for iOS code samples.
Retrieving media data
You can retrieve your video and playlist data from your Video Cloud library by using the Playback API. For details about the API, see the Playback API Overview document.
-
Use the
BCOVPlaybackService
class methods to retrieve your videos and playlists from Brightcove's Playback API. Your requests can supply the video/playlistID
orReferenceID
. This service will make the URL requests and parse the returned data. -
For this request, you will need a Policy Key. If you are not familiar with Policy Keys, see the Policy API Overview document.
Here is an example of how to retrieve a video using the
BCOVPlaybackService
class in Swift:import UIKit import BrightcovePlayerSDK let kViewControllerPlaybackServicePolicyKey = "your policy key" let kViewControllerAccountID = "your account id" let kViewControllerVideoID = "your video id" class ViewController: UIViewController, BCOVPlaybackControllerDelegate { let sharedSDKManager = BCOVPlayerSDKManager.shared() let playbackService = BCOVPlaybackService(accountId: kViewControllerAccountID, policyKey: kViewControllerPlaybackServicePolicyKey) let playbackController :BCOVPlaybackController @IBOutlet weak var videoContainerView: UIView! required init?(coder aDecoder: NSCoder) { playbackController = (sharedSDKManager?.createPlaybackController())! super.init(coder: aDecoder) 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. // Set up our player view. Create 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 requestContentFromPlaybackService() } func requestContentFromPlaybackService() { playbackService?.findVideo(withConfiguration: configuration, parameters: nil), completion: { [weak self] (video: BCOVVideo?, jsonResponse: [AnyHashable: Any]?, error: Error?) -> Void in if let v = video { self.playbackController.setVideos([v] as NSArray) } else { print("ViewController Debug - Error retrieving video: \(error?.localizedDescription ?? "unknown error")") } } } }
For complete samples, see the following:
-
The BCOVVideo object provides video metadata information as shown below:
func requestContentFromPlaybackService() { playbackService?.findVideo(withConfiguration: configuration, parameters: nil), completion: { [weak self] (video: BCOVVideo?, jsonResponse: [AnyHashable: Any]?, error: Error?) -> Void in if let v = video { print("video name: \(v.properties["name"] as AnyObject)") print("video id: \(v.properties["id"] as AnyObject)") print("video thumbnail: \(v.properties["thumbnail"] as AnyObject)") print("video metadata: \(v.properties)") self.playbackController.setVideos([v] as NSArray) } else { print("ViewController Debug - Error retrieving video: \(error?.localizedDescription ?? "unknown error")") } } }
The above
print()
methods return the following media information:
Working with geo-filtered videos
The Brightcove Player SDK for iOS supports geo-filtered videos.
There are two ways you can add geo-filterings to your videos to control which countries they can (or cannot) be viewed in:
In your iOS app, when you retrieve a video using Brightcove's BCOVPlaybackService
class (Playback API) in a country which is geo-filtered for that video, you should see this message:
Error Domain=kBCOVPlaybackServiceErrorDomain Code=3 "(null)"
UserInfo={kBCOVPlaybackServiceErrorKeyAPIHTTPStatusCode=403,
kBCOVPlaybackServiceErrorKeyAPIErrors=
{type = immutable, count = 1, values = (
0 : {type = immutable dict, count = 4,
entries =>
1 : message = {contents = "Access to this resource is forbidden by access policy."}
2 : {contents = "client_geo"} = us
4 : {contents = "error_subcode"} = {contents = "CLIENT_GEO"}
6 : {contents = "error_code"} = {contents = "ACCESS_DENIED"}
}
)}}
Brightcove Player customers
As a Brightcove Player customer, you will supply the URL for your video assets.
Here is an example of adding an array of videos to the playback controller and starting playback:
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!
}
}
For complete samples, see the following:
You now have a basic understanding of the Brightcove Player SDK for iOS. Next, you can walk through the steps of building an app which uses the Player SDK