2-快速集成
更新時間:2024-06-04 17:16:31
1 帳號準備
在整合播放器 SDK 專案之前,請先在 Polyv 官網 註冊帳號,並開通雲端點播服務。
為了播放您帳號下的點播影片,播放器將需要使用到您點播系統中的 userId 和 secretKey,您可以登入點播後台,在 API 介面 中取得參數。
2 環境需求
| 名稱 | 要求 |
|---|---|
| iOS 系統 | iOS 12.0+ |
| CocoaPods | 1.7.0+ |
| 整合工具 | Xcode 11.0+ |
3 整合播放器專案
3.1 匯入通用模組
複製 demo 專案中的 Common 模組到您專案的根目錄下
3.2 匯入 Secenes 通用模組
複製 demo 專案中的 Secenes 模組到您專案的根目錄下
3.5 設定 Podfile
在 Podfile 檔案中,加入以下內容:
pod 'PolyvMediaPlayerSDK', '~> 2.2.0'
pod 'SDWebImage', '4.4.0'
pod 'MJRefresh', '~> 3.5.0'
3.5 跳轉播放頁面
Secenes 模組提供了 2 個頁面,分別是:
PLVDemoVideoFeedViewController是短影片播放頁面,支援上下滑動切換的沉浸式觀看方式PLVDemoVodMediaViewController是長影片播放頁面,支援單一影片的橫豎螢幕播放方式
您可以根據專案實際需求,選擇其中一個頁面作為播放頁面,然後在您專案的任意頁面跳轉到播放頁面。
而 demo 專案中的 PLVEntranceViewController 是專案示範的入口頁面,示範了如何跳轉到短影片播放頁面或長影片播放頁面。
3.6 參數修改
為了播放您帳號下的影片,您需要對專案預設設定的參數進行修改。
demo 專案中,預設設定的影片資料在 AppDelegate.m 當中,您可以對其中的 initMediaPlayerSDK 參數進行修改:
- (void)initMediaPlayerSDK {
// 配置APP账号
// 公共账号
// 注意: 2.1.x版本以下应为PLVVodSettings,请以实际版本情况调用。
PLVVodMediaSettings *settings = [PLVVodMediaSettings settingsWithUserid:@"e97dbe3e64"
readtoken:@""
writetoken:@""
secretkey:@"zMV29c519P"];
settings.logLevel = PLVVodMediaLogLevelAll;
settings.viewerInfos.viewerId = @"用户";
settings.viewerInfos.viewerName = @"User Name";
settings.viewerInfos.viewerAvatar = @"User Avatar Link";
settings.viewerInfos.viewerExtraInfo1 = @"Custom param3";
settings.viewerInfos.viewerExtraInfo2 = @"Custom param4";
settings.viewerInfos.viewerExtraInfo3 = @"Custom param5";
}
同時 demo 專案中,長影片預設設定了可播放的影片,您可以在 PLVEntranceViewController.m 當中調整初始化的影片 Id。
// 长视频观看
- (void)watchVodButtonAction:(id)sender {
PLVDemoVodMediaViewController *vodMediaVC = [[PLVDemoVodMediaViewController alloc] init];
if (PushOrModel) {
vodMediaVC.hidesBottomBarWhenPushed = YES;
vodMediaVC.vid = @"e97dbe3e648aefc2eb6f68b96db9db6c_e"; // 替换自身项目Id
[self.navigationController pushViewController:vodMediaVC animated:YES];
}else{
vodMediaVC.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:vodMediaVC animated:YES completion:nil];
}
}
