Brightcove 在以下 iOS 版本的最新公开版本上提供对最新 iOS SDK 的主动支持:
Brightcove 为以下 iOS 版本提供被动支持:
核心 SDK 已本地化为阿拉伯语 (ar)、英语 (en)、法语 (fr)、德语 (de)、日语 (ja)、韩语 (ko)、西班牙语 (es)、简体中文 (zh-Hans) 和繁体中文中文(zh-Hant)。为了获得本地化的好处,您的应用程序还必须针对相同的语言和区域设置进行本地化。有关更多信息,请参阅自定义本地化部分。
所有 SDK 组件(核心框架和插件框架)均以相同的版本号发布。升级任何单个组件时,请将所有组件升级到同一版本。
对于在 Apple Silicon M1 和通用框架 (.framework) 上使用 Xcode 12 的项目,在为 arm64 模拟器构建项目时会返回构建错误。
*ld: building for iOS Simulator, but linking in dylib built for iOS, file for architecture arm64*
要构建arm64模拟器,请确保arm64
已添加到应用程序目标的“构建设置”选项卡中Any iOS Simulator SDK
的“排除架构”构建设置中。
Brightcove Player SDK 版本 6.10.0 添加了核心子规范和每个插件以支持 XCFrameworks。每个子规范的默认值为/XCFramework
。
Podspec 名称 | 亚种名称 |
---|---|
Brightcove-玩家核心 | Brightcove-播放器-核心/框架 Brightcove-Player-Core/XCFramework |
Brightcove-玩家-DAI | Brightcove-播放器-DAI/框架 Brightcove-播放器-DAI/XCFramework |
Brightcove-Player-FreeWheel | Brightcove-免费轮盘/框架 Brightcove-Player-FreeWheel/XCFramework |
Brightcove-播放器-GoogleCast | Brightcove-播放器-GoogleCast/框架 Brightcove-播放器-GoogleCast/XCFramework |
Brightcove-播放器-IMA | Brightcove-播放器-IMA/框架 Brightcove-播放器-IMA/XCFramework |
Brightcove-玩家-Omniture | Brightcove-播放器-Omniture/框架 Brightcove-Player-Omniture/XCFramework |
Brightcove-玩家脉冲 | Brightcove-玩家脉冲/框架 Brightcove-玩家-Pulse/XCFramework |
Brightcove-播放器-SSAI | Brightcove-播放器-SSAI/框架 Brightcove-播放器-SSAI/XCFramework |
Brightcove-播放器-OpenMeasurement | - |
Brightcove Player SDK 版本 6.12.0 更新了Brightcove-Player-FreeWheel
和Brightcove-Player-Omniture
podspec 以安装动态版本的BrightcovePlayerSDK
。
Podspec 名称 | 框架类型 | 依赖性 |
---|---|---|
Brightcove-玩家核心 | 动态的 | - |
Brightcove-Player-DAI(自 6.12.7 起可用) | 动态的 | Brightcove-玩家核心 |
Brightcove-Player-FreeWheel | 动态的 | iOS 版 Brightcove-Player-Core, 适用于 tvOS 的 Brightcove-Player-Core |
Brightcove-播放器-GoogleCast | 静止的 | Brightcove-玩家核心 |
Brightcove-播放器-IMA | 动态的 | Brightcove-玩家核心 |
Brightcove-玩家-Omniture | 动态的 | Brightcove-玩家核心 |
Brightcove-玩家脉冲 | 动态的 | Brightcove-玩家核心 |
Brightcove-播放器-SSAI | 动态的 | Brightcove-玩家核心, Brightcove-Player-OpenMeasurement(仅适用于开放测量) |
Brightcove-Player-OpenMeasurement(自 6.10.0 起可用) | 动态的 | - |
对受 FairPlay 保护的视频的支持已集成到核心BrightcovePlayerSDK框架中。有关将 FairPlay 与 Brightcove Native Player SDK 结合使用的完整详细信息,请参阅 FairPlay 指南。
对 Sidecar 字幕的支持已集成到核心BrightcovePlayerSDK框架中。有关将 Sidecar Subtitles 与 Brightcove Native Player SDK 结合使用的完整详细信息,请参阅 Sidecar Subtitles 指南。
自版本 6.0.0 起,Brightcove Native Player SDK 允许您下载 HLS 视频,包括受 FairPlay 加密保护的视频,以便稍后在线或离线播放。有关完整详细信息,请参阅应用程序开发人员指南:
iOS 应用程序开发人员使用 FairPlay 进行视频下载和离线播放的指南
Brightcove Player SDK 提供 iOS 和 tvOS 的安装包,作为打包为 Frameworks 和 XCFrameworks 的动态库。 iOS 12.0 及更高版本支持部署。
您可以使用 CocoaPods 将 Brightcove Player SDK 添加到您的项目中。您可以在此处找到最新的Brightcove-Player-Core
podspec。 podspec 同时支持 iOS 和 tvOS。
在项目中使用 Brightcove CocoaPods 时,请将source 'https://github.com/brightcove/BrightcoveSpecs.git'
添加到 Podfile 的开头。
姓名。
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
可以通过将/Framework
规范附加到 pod 来安装框架。
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
更新安装时,最好刷新 BrightcoveSpecs 存储库的本地副本,以便您在本地拥有最新的 podspec,就像更新 CococaPods 主存储库一样。通常,如果您在终端中运行pod update
这将自动发生,或者您可以使用pod repo update
显式更新。
要将 Brightcove Player SDK 手动添加到您的项目中:
BrightcovePlayerSDK.framework
或BrightcovePlayerSDK.xcframework
添加到您的项目中。请务必使用与您的目标、iOS 或 tvOS 相对应的版本。BrightcovePlayerSDK.framework
/ BrightcovePlayerSDK.xcframework
bash ${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/BrightcovePlayerSDK.framework/strip-frameworks.sh
添加“运行脚本”阶段。选中“仅在安装时运行脚本”。这将从构建中删除不需要的架构,这对于 App Store 提交非常重要。使用 XCFramework 时不再需要此步骤。bash ${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/BrightcovePlayerSDK.framework/strip-frameworks.sh
添加“运行脚本”阶段。选中“仅在安装时运行脚本”。这将从构建中删除不需要的架构,这对于 App Store 提交非常重要。arm64
已添加到Any iOS Simulator SDK
的“排除架构”构建设置中。作为参考,以下是所有 SDK 组件和相应的 URL,可帮助您查找和下载最新版本:
成分 | 网址 |
---|---|
Brightcove-玩家核心 | https://github.com/brightcove/brightcove-player-sdk-ios/tags |
Brightcove-玩家-DAI | https://github.com/brightcove/brightcove-player-sdk-ios-dai/tags |
Brightcove-Player-FreeWheel | https://github.com/brightcove/brightcove-player-sdk-ios-fw/tags |
Brightcove-播放器-GoogleCast | https://github.com/brightcove/brightcove-player-sdk-ios-googlecast/tags |
Brightcove-播放器-IMA | https://github.com/brightcove/brightcove-player-sdk-ios-ima/tags |
Brightcove-玩家-Omniture | https://github.com/brightcove/brightcove-player-sdk-ios-omniture/tags |
Brightcove-玩家脉冲 | https://github.com/brightcove/brightcove-player-sdk-ios-pulse/tags |
Brightcove-播放器-SSAI | https://github.com/brightcove/brightcove-player-sdk-ios-ssai/tags |
要使用 Swift Package Manager 将 Brightcove Player SDK 添加到您的项目中:
https://github.com/brightcove/brightcove-player-sdk-ios.git
注意:Swift Package Manager 仅支持动态 XCFramework。
适用于 iOS 的 Brightcove Player SDK 可以使用以下方式导入:
import BrightcovePlayerSDK;
使用适用于 iOS 的 Brightcove Player SDK 播放视频:
// ** 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 ( )
}
}
您需要防止控制器在方法结束时自动释放。执行此操作的常见方法是将控制器的引用存储在强实例变量中。
从5.1.0版本开始,Brightcove PlayerUI完全集成到Core SDK框架中。 PlayerUI 提供了一套功能齐全的播放和广告控件,开箱即用。
PlayerUI 可以快速设置,显示 SSAI、Pulse 和 FreeWheel 的广告控件,并且可以通过创建自己的布局进行自定义。
请遵循以下指南来设置 PlayerUI 控件。
在 UIViewController 中创建一个属性来跟踪 BCOVPUIPlayerView。 BCOVPUIPlayerView 将包含播放控制器的视图和控件视图。
// PlayerUI's Player View
var playerView : BCOVPUIPlayerView ?
创建 BCOVPUIBasicControlView,然后创建 BCOVPUIBasicControlView。这是我们将播放控制器(以及它播放的所有视频)与控件关联起来的地方。
// Create and configure Control View.
let controlView = BCOVPUIBasicControlView . withVODLayout ( )
playerView = BCOVPUIPlayerView ( playbackController : self . playbackController , options : nil )
// Add BCOVPUIPlayerView to your video view.
if let playerView {
videoView . addSubview ( playerView )
}
您需要设置播放器视图的布局,可以使用自动布局或旧的 Springs & Struts 方法来完成此操作。
设置播放器视图,使其在调整大小时与布局 ( videoView
) 中的视频容器相匹配。
playerView . frame = videoView . bounds
playerView . autoresizingMask = [ . flexibleHeight , . flexibleWidth ]
将 BCOVPUIPlayerView 上的translatesAutoresizingMaskIntoConstraints
设置为false
。
playerView . translatesAutoresizingMaskIntoConstraints = false
然后添加布局的约束;将 BCOVPUIPlayerView 的顶部、右侧、左侧和底部锚点设置为等于videoView
的锚点
NSLayoutConstraint . activate ( [
playerView . topAnchor . constraint ( equalTo : videoView . topAnchor ) ,
playerView . rightAnchor . constraint ( equalTo : videoView . rightAnchor ) ,
playerView . bottomAnchor . constraint ( equalTo : videoView . bottomAnchor ) ,
playerView . leftAnchor . constraint ( equalTo : videoView . leftAnchor )
] )
BCOVPUIPlayerViewOptions
类允许您在初始化时自定义一些 BCOVPlayerUI 行为。您可以自定义以下内容:
jumpBackInterval
按下跳回按钮时播放器将向后查找的时间(以秒为单位)。
hideControlsInterval
最后一次触摸事件之后、隐藏控件之前的时间(以秒为单位)。
hideControlsAnimationDuration
控件以动画方式隐藏所需的时间(以秒为单位)。
showControlsAnimationDuration
控件动画显示所需的时间(以秒为单位)。
learnMoreButtonBrowserStyle
用于确定点击广告上的“了解更多”按钮是否会在外部浏览器(默认设置)或内部浏览器中显示点击链接的设置。
presentingViewController
用于呈现其他视图控制器(如隐藏式字幕选择视图控制器)的 UIViewController 子类。
automaticControlTypeSelection
您是否希望BCOVPUIPlayerView
根据媒体类型自动选择BCOVPUIBasicControlView
类型。当此值设置为true
时,传递到BCOVPUIBasicControlView
初始值设定项的BCOVPUIPlayerView
属性将被忽略。
视频+音频流
basicControlViewWithVODLayout
basicControlViewWithLiveLayout
basicControlViewWithLiveDVRLayout
纯音频流
basicControlViewWithAODLayout
basicControlViewWithLiveAudioLayout
basicControlViewWithLiveDVRAudioLayout
注意: automaticControlTypeSelection
从 BCOVPlayerUI 提供的布局中选择布局,因此自定义控件和布局将被覆盖; automaticControlTypeSelection
和播放器 UI 自定义不兼容。
可以使用以下方法设置选项:
let manager = BCOVPlayerSDKManager . sharedManager ( )
let playbackController = manager . createPlaybackController ( )
let options = BCOVPUIPlayerViewOptions ( )
options . jumpBackInterval = 5
let playerView = BCOVPUIPlayerView ( playbackController : playbackController ,
options : options )
提供三种布局来支持不同类型的视频:
BCOVPUIControlLayout basicVODControlLayout
是一般点播视频流的基本布局。
BCOVPUIControlLayout basicLiveControlLayout
是直播视频的布局。
BCOVPUIControlLayout basicLiveDVRControlLayout
是带有 DVR 控件的实时视频流的布局。
您通常在创建BCOVPUIPlayerView
后立即设置新布局,但也可以随时设置新布局。例如,您可以像这样设置新的 VOD 布局:
playerView ? . controlsView . layout = BCOVPUIControlLayout . basicVOD ( )
除了默认布局之外,您还可以通过使用自己的设计实例化新的BCOVPUIControlLayout
来创建自己的高度自定义布局。但请注意, automaticControlTypeSelection
从 BCOVPlayerUI 提供的布局中选择布局,因此自定义控件和布局将被覆盖; automaticControlTypeSelection
和播放器 UI 自定义不兼容。
首先,使用BCOVPUIBasicControlView layoutViewWithControlFromTag:width:elasticity:
创建将进入布局的控件。每个控件都封装在BCOVPUILayoutView
中,该视图确定控件间距。
您可以将每个布局视图的width
设置为默认宽度(基于控件的类型),也可以指定您自己的宽度。
使用elasticity
参数来确定包含控件的布局视图调整其宽度以填充控制栏的程度。
以下是创建各种基本控件的示例。
// Create various standard layout views
// Standard play/pause button
let playbackLayoutView = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . buttonPlayback ,
width : kBCOVPUILayoutUseDefaultValue ,
elasticity : 0.0 )
// Standard jump back button
let jumpBackButtonLayoutView = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . buttonJumpBack ,
width : kBCOVPUILayoutUseDefaultValue ,
elasticity : 0.0 )
// Current time indicator
let currentTimeLayoutView = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . labelCurrentTime ,
width : kBCOVPUILayoutUseDefaultValue
elasticity : 0.0 )
// Time separator - typically the '/' character
let timeSeparatorLayoutView = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . labelTimeSeparator ,
width : kBCOVPUILayoutUseDefaultValue ,
elasticity : 0.0 )
// Video duration label
let durationLayoutView = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . labelDuration ,
width : kBCOVPUILayoutUseDefaultValue ,
elasticity : 0.0 )
// Slider bar used for seeking through the video
// The elasticity is set to 1 so that it can resize to fill available space
let progressLayoutView = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . sliderProgress ,
width : kBCOVPUILayoutUseDefaultValue ,
elasticity : 1.0 )
// Closed caption button
// This button is initially hidden ('removed'), and will be shown
// if closed captions or audio tracks are available.
let closedCaptionLayoutView = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . buttonClosedCaption ,
width : kBCOVPUILayoutUseDefaultValue ,
elasticity : 0.0 )
closedCaptionLayoutView ? . isRemoved = true
// The full-screen button
let screenModeLayoutView = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . buttonScreenMode ,
width : kBCOVPUILayoutUseDefaultValue ,
elasticity : 0.0 )
// AirPlay button
// This button is initially hidden ('removed'), and will be shown
// if AirPlay devices are available.
let externalRouteLayoutView = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . viewExternalRoute ,
width : kBCOVPUILayoutUseDefaultValue ,
elasticity : 0.0 )
externalRouteLayoutView ? . isRemoved = true
// Empty view - used as a spacer
let spacerLayoutView1 = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . viewEmpty ,
width : 1.0 ,
elasticity : 1.0 )
// Empty view - used as a spacer
let spacerLayoutView2 = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . viewEmpty ,
width : 1.0 ,
elasticity : 1.0 )
// Empty view - will have a custom UIImageView added as a subview
let logoLayoutView1 = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . viewEmpty ,
width : 88.0 ,
elasticity : 1.0 )
// Empty view - will have a custom UIImageView added as a subview
let logoLayoutView2 = BCOVPUIBasicControlView . layoutViewWithControl ( from : BCOVPUIViewTag . viewEmpty ,
width : 36.0 ,
elasticity : 1.0 )
请注意,您还可以创建一个空布局视图,在其中可以放置您自己的视图(徽标、控件、无内容等)。此代码展示了如何将UIImage
徽标放置在我们上面创建的 logoLayoutView1 中。
// Create logo image inside an image view for display in control bar.
let logoImage1 = UIImage ( named : " myLogo " )
let logoImageView1 = UIImageView ( image : logoImage1 )
logoImageView1 . autoresizingMask = [ . flexibleWidth , . flexibleHeight ]
logoImageView1 . contentMode = . scaleAspectFit
logoImageView1 . frame = logoLayoutView1 . frame
// Add image view to our empty layout view.
logoLayoutView1 . addSubview ( logoImageView1 )
现在布局视图中封装了各种控件,它们被排序成数组,每个数组代表一行控件,即一个控件栏。请注意,纵向和横向可以有不同的布局,因此您通常会设置两个不同的控制栏阵列。
在横向的标准布局中,控件排列在单个数组中,然后该数组存储在表示整个控件集的另一个数组中。
let standardLayoutLine1 = [
playbackLayoutView ,
jumpBackButtonLayoutView ,
currentTimeLayoutView ,
timeSeparatorLayoutView ,
durationLayoutView ,
progressLayoutView ,
spacerLayoutView1 ,
logoLayoutView1 ,
spacerLayoutView2 ,
closedCaptionLayoutView ,
screenModeLayoutView ,
externalRouteLayoutView
]
let standardLayoutLines = [ standardLayoutLine1 ]
在纵向的紧凑布局中,创建了两个控件数组,每一行一个。这些数组被打包到另一个表示紧凑布局的数组中。
请注意,每个布局中的大多数控件都使用完全相同的对象。完成此操作后,当您在纵向和横向之间切换时,对象将使用平滑的动画移动到新位置。
let compactLayoutLine1 = [
currentTimeLayoutView ,
progressLayoutView ,
durationLayoutView
]
let compactLayoutLine2 = [
playbackLayoutView ,
jumpBackButtonLayoutView ,
spacerLayoutView1 ,
closedCaptionLayoutView ,
screenModeLayoutView ,
externalRouteLayoutView ,
logoLayoutView2
]
let compactLayoutLines = [
compactLayoutLine1 ,
compactLayoutLine2
]
最后,现在有两种布局配置(一种用于全宽度,一种用于紧凑宽度),您可以创建一个新的BCOVPUIControlLayout
对象,并将其设置在播放器的控制视图中。
let customLayout = BCOVPUIControlLayout . init ( standardControls : standardLayoutLines ,
compactControls : compactLayoutLines )
playerView ? . controlsView . layout = customLayout
如果您有需要频繁显示或隐藏的控件,则可以在该控件的布局视图上设置removed
属性。当你改变了你的控件后,在playerView的controlView上调用setNeedsLayout
:
logoLayoutView1 ? . isRemoved = true
playerView ? . controlsView . setNeedsLayout ( )
您还可以自定义几个常规BCOVPUIControlLayout
属性:
controlBarHeight
设置每行控件的大小。horizontalItemSpacing
设置每个控制栏中每个BCOVPUILayoutView
之间的间距。compactLayoutMaximumWidth
确定使用哪一组控件。如果控件视图小于compactLayoutMaximumWidth
,则将使用紧凑控件集,否则将使用标准控件。要更改显示的控件集,您必须创建并安装新的BCOVPUIControlLayout
。可以随时安装新的控件。
有关 PlayerUI 自定义的更多示例,您可以查看 BrightcoveOS GitHub 存储库的 PlayerUI 文件夹中的示例代码:
https://github.com/BrightcoveOS/ios-player-samples
Brightcove Native Player SDK 包括用于在 Apple TV 上的 tvOS 中播放的内置控件。有关将内置电视播放器 UI 与 Brightcove Native Player SDK 结合使用的完整详细信息,请参阅我们的电视播放器指南。
通过将BCOVPlaybackController
上的setAllowsExternalPlayback
属性设置为true
来启用 AirPlay 功能。如果在网络上找到 AirPlay 设备,则播放控件中将显示 AirPlay 按钮。
目前,IMA 是唯一支持 AirPlay 的广告插件,并且仅在使用前贴片和/或后贴片广告时才支持。将 AirPlay 与 Pulse、SSAI 或 FreeWheel 广告插件一起使用可能会导致意外行为。
如果您还想支持 AirPlay 2 并允许选择多个设备进行音频输出,您将需要做一些额外的事情。首先,您需要配置 AVAudioSession ,以便可以设置routeSharingPolicy
。例如:
do {
try AVAudioSession . sharedInstance ( ) . setCategory ( . playback , mode : . moviePlayback , policy : . longFormVideo )
} catch {
print ( " Error setting AVAudioSession category " )
}
您还需要通过MPRemoteCommandCenter
配置至少一个播放命令。至少您需要配置pauseCommand
和playCommand
。例如:
let center = MPRemoteCommandCenter . shared ( )
center . pauseCommand . addTarget { _ in
playbackController . pause ( )