测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | 商业 |
发布上次发布 | 2016年6月 |
由Steve Bushell、Jim Whisenant、Tim Rodgers维护。
iOS 7.0及以上。
Brightcove PlayerUI插件为iOS提供两个安装包,一个静态库框架和一个动态框架。静态库目标支持iOS 7的部署,而动态框架仅支持iOS 8及以上。
要将Brightcove Player SDK的PlayerUI插件手动添加到项目中
BrightcovePlayerUI.framework
bash ${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/BrightcovePlayerUI.framework/strip-frameworks.sh
。选中"仅安装时运行脚本"。这将删除构建中不需要的架构,这对于App Store提交非常重要。([rdar://19209161][19209161])-ObjC
添加到"其他链接器标志"构建设置中。BrightcovePlayerUI.framework
打包的文件 bcovpuiiconfont.ttf
添加到您的项目列表中,这样字体文件就会被复制到应用程序包中。最终,该字体文件应与应用程序的 Info.plist
文件位于同一级别。字体文件提供了 BrightcovePlayerUI 部分界面元素,但无需在 plist 文件中列出。可将 iOS 的 Brightcove Player SDK 以几种不同方式导入到代码中;使用 @import BrightcovePlayerUI;
,#import <BrightcovePlayerUI/BrightcovePlayerUI.h>
或 #import <BrightcovePlayerUI/[specific class].h>
。
其使用相对简单。以下示例创建了一个适用于常规按需视频流的基�始化布局:
BCOVPlayerSDKManager *manager = [BCOVPlayerSDKManager sharedManager];
[1] id<BCOVPlaybackController> controller = [manager createPlaybackController];
[2] BCOVPUIPlayerView *playerView = [[BCOVPUIPlayerView alloc] initWithPlaybackController:playbackController];
playerView.frame = self.videoContainer.bounds;
playerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.videoContainer addSubview:playerView];
[3] NSString *token; // (Brightcove Media API token with URL access)
NSString *playlistID; // (ID of the playlist you wish to use)
BCOVCatalogService *catalog = [[BCOVCatalogService alloc] initWithToken:token];
[catalog findPlaylistWithPlaylistID:playlistID
parameters:nil
completion:^(BCOVPlaylist *playlist,
NSDictionary *jsonResponse,
NSError *error) {
[controller setVideos:playlist];
[controller play];
}];
以下是逐步分解此代码,以便更容易理解
BCOVPlayerUI插件提供了一种现成的体验。然而,可以更改默认行为。
BCOVPUIPlayerViewOptions
类允许您在初始化时自定义一些 BCOVPlayerUI 行为。您可以自定义:
jumpBackInterval
当按下返回按钮时,播放器将跳回的秒数。hideControlsInterval
在最后的事件触摸后面的秒数,在控件被隐藏之前。hideControlsAnimationDuration
控件动画到隐藏所需的时间(秒)。showControlsAnimationDuration
控件动画到可见所需的时间(秒)。presentingViewController
用于显示模态和全屏等功能视图控制器。可以使用以下方法设置选项:
BCOVPlayerSDKManager *manager = [BCOVPlayerSDKManager sharedManager];
id<BCOVPlaybackController> controller = [manager createPlaybackController];
BCOVPUIPlayerViewOptions *options = [[BCOVPUIPlayerViewOptions alloc] init];
options.jumpBackInterval = 5;
BCOVPUIPlayerView *playerView = [[BCOVPUIPlayerView alloc] initWithPlaybackController:playbackController options:options];
提供了三种布局以支持不同类型的视频。
BCOVPUIControlLayout basicVODControlLayout
是一般按需视频流的基布局。
BCOVPUIControlLayout basicLiveControlLayout
针对直播视频。
BCOVPUIControlLayout basicLiveDVRControlLayout
针对带有 DVR 控件的直播视频流。
通常在创建 BCOVPUIPlayerView
后立即设置新的布局,但您也可以在任何时候设置新的布局。例如,您可以这样设置新的 VOD 布局:
playerview.controlView.layout = [BCOVPUIControlLayout basicVODControlLayout]
除了默认布局之外,您还可以通过用您自己的设计实例化新的 BCOVPUIControlLayout
来创建高度自定义的布局。
首先,使用 BCOVPUIBasicControlView layoutViewWithControlFromTag:width:elasticity:
创建将放入布局中的控件。每个控件都包装在一个 BCOVPUILayoutView
中,该视图确定控件的间距。您可以设置每个布局视图的宽度为默认宽度(基于控件的类型),或指定您自己的宽度。
弹性(elasticity
)参数决定了包含控件的布局视图如何调整其宽度以填充控件栏。弹性值为零意味着布局视图的大小将保持不变。大于零的弹性值决定了相对于同一控件栏中其他弹性视图,布局视图将增长以填充剩余空间的多少。弹性值为2.0的布局视图将比弹性值为1.0的布局视图增长速度快两倍。通常,一行布局视图至少有一个弹性值大于零的控件。
以下是创建各种基本控件的示例。
BCOVPUILayoutView *playbackLayoutView = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagButtonPlayback width:kBCOVPUILayoutUseDefaultValue elasticity:0.0];
BCOVPUILayoutView *jumpBackButtonLayoutView = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagButtonJumpBack width:kBCOVPUILayoutUseDefaultValue elasticity:0.0];
BCOVPUILayoutView *currentTimeLayoutView = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagLabelCurrentTime width:kBCOVPUILayoutUseDefaultValue elasticity:0.0];
BCOVPUILayoutView *timeSeparatorLayoutView = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagLabelTimeSeparator width:kBCOVPUILayoutUseDefaultValue elasticity:0.0];
BCOVPUILayoutView *durationLayoutView = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagLabelDuration width:kBCOVPUILayoutUseDefaultValue elasticity:0.0];
BCOVPUILayoutView *progressLayoutView = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagSliderProgress width:kBCOVPUILayoutUseDefaultValue elasticity:1.0];
BCOVPUILayoutView *closedCaptionLayoutView = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagButtonClosedCaption width:kBCOVPUILayoutUseDefaultValue elasticity:0.0];
BCOVPUILayoutView *screenModeLayoutView = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagButtonScreenMode width:kBCOVPUILayoutUseDefaultValue elasticity:0.0];
BCOVPUILayoutView *externalRouteLayoutView = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagViewExternalRoute width:kBCOVPUILayoutUseDefaultValue elasticity:0.0];
BCOVPUILayoutView *spacerLayoutView1 = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagViewEmpty width:1.0 elasticity:1.0];
BCOVPUILayoutView *spacerLayoutView2 = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagViewEmpty width:1.0 elasticity:1.0];
BCOVPUILayoutView *logoLayoutView1 = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagViewEmpty width:80.0 elasticity:1.0];
BCOVPUILayoutView *logoLayoutView2 = [BCOVPUIBasicControlView layoutViewWithControlFromTag:BCOVPUIViewTagViewEmpty width:36.0 elasticity:0.0];
// Hide closed caption and AirPlay controls until explicily needed.
closedCaptionLayoutView.removed = YES;
externalRouteLayoutView.removed = YES;
注意您也可以创建一个空的布局视图,然后在其中放置自己的视图(标志、控件、无等)。以下代码显示了如何将UIImage标志放置在我们上面创建的logoLayoutView1中。
// Create logo image inside an image view for display in control bar.
UIImage *logoImage1 = [UIImage imageNamed:@"myLogo"];
UIImageView *logoImageView1 = [[UIImageView alloc] initWithImage:logoImage1];
logoImageView1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
logoImageView1.contentMode = UIViewContentModeScaleAspectFit;
logoImageView1.frame = logoLayoutView1.frame;
// Add image view to our empty layout view.
[logoLayoutView1 addSubview:logoImageView1];
现在我们已经将控件包装在布局视图中,我们可以将它们排列成数组,其中每个数组代表一行控件,即控件栏。请注意,您可以根据横向和纵向方向设置不同的布局,所以您通常将设置两个不同的控件栏数组。
在标准的横向布局中,我们将我们的控件排列成一行,然后将该数组合并到另一个表示整个配置的数组中。
NSArray *standardLayoutLine1 = @[ playbackLayoutView, jumpBackButtonLayoutView, currentTimeLayoutView, timeSeparatorLayoutView, durationLayoutView, progressLayoutView, spacerLayoutView1, logoLayoutView1, spacerLayoutView2, closedCaptionLayoutView, screenModeLayoutView, externalRouteLayoutView ];
NSArray *standardLayoutLines = @[ standardLayoutLine1 ];
在紧凑布局中,对于纵向方向,我们创建两个控件数组,然后这两个数组被包装到另一个表示紧凑布局的数组中。
请注意,我们在大多数控件中使用的是完全相同的对象。当这样做,并在纵向和横向方向之间切换时,对象将使用平滑动画移动到其新位置。
NSArray *compactLayoutLine1 = @[ currentTimeLayoutView, progressLayoutView, durationLayoutView ];
NSArray *compactLayoutLine2 = @[ playbackLayoutView, jumpBackButtonLayoutView, spacerLayoutView1, closedCaptionLayoutView, screenModeLayoutView, externalRouteLayoutView, logoLayoutView2 ];
NSArray *compactLayoutLines = @[ compactLayoutLine1, compactLayoutLine2 ];
最后,现在我们有两个布局配置:一个用于全宽,一个用于紧凑宽度,我们可以创建一个新的BCOVPUIControlLayout
对象,并将其设置在玩家的控件视图中。
BCOVPUIControlLayout *customLayout = [[BCOVPUIControlLayout alloc] initWithStandardControls:standardLayoutLines compactControls:compactLayoutLines];
playerView.controlView.layout = customLayout;
如果您需要频繁显示或隐藏控件,您可以在该控件的布局视图中设置removed
属性。当您更改控件时,请调用玩家视图的控件视图中的setNeedsLayout
logoLayoutView1.removed = YES;
[playerView.controlsView setNeedsLayout];
您还可以自定义几个通用的 BCOVPUIControlLayout
属性
controlBarHeight
设置了每行控件的大小。horizontalItemSpacing
设置了每个控件栏中BCOVPUILayoutView
之间的间隔。compactLayoutMaximumWidth
确定了哪个控件集被使用。如果控件视图小于compactLayoutMaximumWidth
,则使用紧凑控件集,否则使用标准控件。要更改要显示的控件集,您必须创建并安装一个新的BCOVPUIControlLayout
。
**这适用于所有Brightcove Player SDK插件吗?**
本次版本支持基本VOD、直播和直播DVR播放而不带广告。我们将在未来的版本中添加对其他插件的支持。
**我如何自定义上述提到的属性?**
我们的目标是创建一个既容易自定义,又能提供大量功能和行为的工具。在未来的版本中,我们将通过新的API和更多文档来介绍更多的自定义。如果您有需要的功能,请在我们的论坛中告诉我们。
**未来版本会有API的重大变化吗?**
我们将尽力不进行更改,除非我们确实需要。但是,如果我们确实需要API更改,我们将在CHANGELOG中提供清晰的迁移步骤。