Video player SDK for iOS
You can embed a video player with Cloud Video content into your mobile app for iOS. The video player SDK for iOS will help you do this.
To use the SDK, install and configure the Xcode
Adding a video player SDK library
-
In the Project Navigator Xcode window, select your project.
-
In the top panel, click File and select Add Package Dependencies....
-
In the search box
, enterhttps://github.com/yandex-cloud/cloud-video-player-ios-sdk/. Then, select thecloud-video-player-ios-sdkpackage. -
In the Dependency Rule field, select Up to Next Major Version and specify the version:
0.1.0-beta. -
In the Add to Project field, select the project you want to add libraries to and click Add Package.
-
In the pop-up window, specify the target to add the libraries to and click Add Package.
The package contains the following libraries:
CloudVideoPlayer: Main library of the video player SDK for iOS.CloudVideoPlayerUI: Additional library with a collection of interface elements (video player skin).
-
In the Project Navigator Xcode window, select your project.
-
Open
Package.swift. -
Add the following dependency to the
dependenciesarray:dependencies: [ .package( url: "https://github.com/yandex-cloud/cloud-video-player-ios-sdk/", from: "0.1.0-beta" ) ], -
Add the libraries to the
dependenciesarray of the target:.target( name: "MyTargetName", dependencies: [ .product(name: "CloudVideoPlayer", package: "cloud-video-player-ios-sdk"), .product(name: "CloudVideoPlayerUI", package: "cloud-video-player-ios-sdk") ] ),Where:
CloudVideoPlayer: Main library of the video player SDK for iOS.CloudVideoPlayerUI: Additional library with a collection of interface elements (video player skin).
-
Save your changes.
Importing the libraries
To import the libraries, add the following lines to your code file:
import CloudVideoPlayer
import CloudVideoPlayerUI
Using the SDK
Set up the start of playback
-
Import a library in the file:
import CloudVideoPlayer -
Create the
EnvironmentandYaPlayerobjects:let environment = Environment(from: From(raw: "you-app-bundle")) class ViewController: UIViewController { let player = environment.player() } -
Create the
VideoSurfaceUIView component, add it to the hierarchy, and attach to the player instance:let surface = VideoSurface() override func loadView() { super.loadView() self.view.addSubview(surface) surface.frame = UIScreen.main.bounds } override func viewDidLoad() { super.viewDidLoad() surface.attach(player: player) } -
Start playback:
player.set(source: ContentId(rawValue: "https://runtime.video.cloud.yandex.net/player/...")) player.play()
Where:
https://runtime.video.cloud.yandex.net/player/...: Link to playable content, e.g.,https://runtime.video.cloud.yandex.net/player/video/vplvmyqsxi7dlwndvb4y. For more information, see these sections:
Full code to set up the start of playback
import CloudVideoPlayer
let environment = Environment(from: From(raw: "you-app-bundle"))
class ViewController: UIViewController {
let player = environment.player()
let surface = VideoSurface()
override func loadView() {
super.loadView()
self.view.addSubview(surface)
surface.frame = UIScreen.main.bounds
}
override func viewDidLoad() {
super.viewDidLoad()
surface.attach(player: player)
player.set(source: ContentId(rawValue: "https://runtime.video.cloud.yandex.net/player/..."))
player.play()
}
}
Where:
https://runtime.video.cloud.yandex.net/player/...: Link to playable content, e.g.,https://runtime.video.cloud.yandex.net/player/video/vplvmyqsxi7dlwndvb4y. For more information, see these sections:
Connecting a video player skin
-
Import a library in the file:
import CloudVideoPlayerUI -
Create the
VideoViewUIView component, add it to the hierarchy, and connect to the player instance:let videoView = VideoView() override func loadView() { super.loadView() self.view.addSubview(surface) videoView.frame = UIScreen.main.bounds } override func viewDidLoad() { super.viewDidLoad() videoView.attach(player: player) }
Full code to connect a video player skin
import CloudVideoPlayerUI
let videoView = VideoView()
override func loadView() {
super.loadView()
self.view.addSubview(surface)
videoView.frame = UIScreen.main.bounds
}
override func viewDidLoad() {
super.viewDidLoad()
videoView.attach(player: player)
}