THEOplayerSDK
THEOplayerSDK 将由 THEO Technologies 创建的通用视频播放解决方案带到了iOS和tvOS,使您能够快速实现跨平台内容播放。
先决条件
Cocoapods
您必须已安装 Cocoapods。您可以通过遵循 Cocoapods 安装指南 或使用 Brew 来安装 Cocoapods。
THEOplayer 许可证
您必须具备有效的 THEOplayer 许可证。通过访问 https://portal.theoplayer.com 请求您的许可证,在那里您可以创建 THEOplayer iOS SDK。创建 iOS SDK 后,您可以将其许可证字符串复制到剪贴板,如下面的截图所示。设置 THEOplayer 时必须使用此许可证字符串。
包含的功能
THEOplayerSDK 由模块化功能组成。此包仅包含基本功能:hls、ui 和 airplay。
未来将提供更多功能集。
或者,您可以通过我们的 THEOportal 创建自己的自定义构建。
安装
在向 Podfile 添加新的 pods 之前运行 pod repo update
是一种良好的做法。
这将通过更新对公共规范仓库的引用列表来查找新添加的 pods。
如果您刚刚安装了 Cocoapods 或已更新,则可以跳过此步骤。
将 pod 'THEOplayerSDK-basic', '~> 2.82'
添加到 Podfile 中,如下所示
target 'MyApp' do
pod 'THEOplayerSDK-basic', '~> 2.82'
end
请注意,您可以将 ~> 2.82
省略以获取 THEOplayerSDK 的最新发布版本。
然后,使用终端导航到 Podfile 所在的目录,并运行
pod install
请注意,版本早于 2.82.0(发布 2021.1.2)的版本在公共 Cocoapods 注册表中不可用。
早期版本可通过我们的 THEOportal 获取。
使用方法
将 THEOplayerSDK 框架导入到 swift 文件中
import THEOplayerSDK
接下来,使用 THEOplayer 初始化器之一创建一个播放器实例,并为其提供一个 frame 和一个 source。
以下两个示例演示了如何通过 UIKit 和 SwiftUI 设置 THEOplayer。请注意这两个示例中的 "your_license_here"
占位符。您需要将此字符串替换为“先决条件”中提到的许可证字符串。
UIKit
以下是基于 UIKit
的应用程序视图控制器中的代码显示
class ViewController: UIViewController {
var playerConfig = THEOplayerConfiguration(pip: PiPConfiguration(), license: "your_license_here")
var player = THEOplayer(configuration: playerConfig)
func setupPlayer() {
let playerFrame = CGRect(x: 0, y: 0, width: 320, height: 180)
let source = "https://cdn.theoplayer.com/video/big_buck_bunny/big_buck_bunny.m3u8"
let mimeType = "application/x-mpegurl"
player.frame = playerFrame
player.center = view.center
player.source = SourceDescription(source: TypedSource(src: source, type: mimeType))
}
override func viewDidLoad() {
super.viewDidLoad()
setupPlayer()
player.addAsSubview(of: self.view)
}
}
请注意,player
变量声明为 ViewController 类的属性。
这是为了保持对 player 对象的强引用。
SwiftUI
以下是基于 SwiftUI
的应用程序内容视图中的代码显示
struct THEOplayerWrapper: UIViewRepresentable {
var playerConfig = THEOplayerConfiguration(pip: PiPConfiguration(), license: "your_license_here")
var player = THEOplayer(configuration: playerConfig)
func setupPlayer() {
let playerFrame = CGRect(x: 0, y: 0, width: 320, height: 180)
let source = "https://cdn.theoplayer.com/video/big_buck_bunny/big_buck_bunny.m3u8"
let mimeType = "application/x-mpegurl"
player.frame = playerFrame
player.source = SourceDescription(source: TypedSource(src: source, type: mimeType))
}
func makeUIView(context: Context) -> UIView {
setupPlayer()
let playerView = UIView()
player.addAsSubview(of: playerView)
return playerView
}
func updateUIView(_ uiView: UIView, context: Context) {
// make necessary updates
}
}
struct ContentView: View {
var body: some View {
VStack {
Text("THEOplayer Sample")
THEOplayerWrapper()
}
}
}
这就完成了!现在您的应用程序应该已经有了可用的播放器。
文档
THEOplayer 的文档位于我们的 文档网站 上。关于如何设置 THEOplayer 的示例,请参阅我们的 入门指南。
支持
如果您在安装或使用该软件包时遇到问题,首先请查找我们文档网站上的现有答案,尤其是我们的常见问题解答。
您还可以通过我们支持页面上的说明联系我们的技术支持团队。请注意,您的支持水平取决于您选择的支持方案。
常见问题解答
为什么我会收到“找不到模块'THEOplayerSDK'”或其他类似错误?
这可能是以下原因之一
- 您错误地配置了您的
Podfile
,或者忘记运行pod install --repo-update
以安装您的Podfile
。 - 您使用了较旧的CocoaPods版本。您可以通过
pod --version
检查您的版本。运行(sudo) gem install cocoapods
以升级到最新版本。 - 您打开的是您的
xcodeproj
而不是您的xcworkspace
。(请打开您的xcworkspace
!) - Xcode行为异常。关闭您的 Workspace,通过
pod deintegrate
卸载您的 pods,然后再通过pod install --repo-update
重新安装。
许可证
本软件包的内容受THEOplayer许可证的约束。