- Print
- PDF
For iOS
- Print
- PDF
Available in Classic and VPC
Describes how to use Video Player Enhancement iOS SDK for Android players and apply players and setting options in the iOS environment.
To use the Video Player Enhancement SDK for iOS, you must use the Standard pricing plan, which requires the following specifications:
- Minimum requirement: iOS 14.0 or later
- Development environment: Xcode
Install SDK and configure environment
The following describes how to install the SDK and add the framework:
- Click the environment you are using in the Region menu and the Platform menu on the NAVER Cloud Platform console.
- Click Services > Media > Video Player Enhancement.
- Click the Video Player Management menu.
- Click the [SDK Address] button for the player to download the SDK in the player’s list.
- Click the [IOS] button in Downloading mobile native SDKs.
- The zipped files will be downloaded.
- Click the Targets > General menu for the project you want to add after running Xcode.
- In Framework, Libraries, and Embedded Content, add "NCPlayerSDK.xcframework" as Embed & Sign type.
Apply and set the player
To apply a player and set options, proceed with the following steps:
1. Reset
You should initialize the NCPlayerSDK instance and set Delegate as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
...
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
NCPlayer.shared.delegate = self
}
}
2. Player settings
The following describes how to set up the player:
Click the environment you are using in the Region menu and the Platform menu on the NAVER Cloud Platform console.
Click Services > Media > Video Player Enhancement.
Click the Video Player Management menu.
Click the [SDK address] button on the player you want to set up.
When the Player SDK address prompt appears, view the access_key value in the SDK address.
In the Xcode, create Class and UIView that refers the NCPlayerView.
Set options for the player.
- See Player settings and configuration script in this guide.
class player:NCPlayerView{} class ViewController: UIViewController, NCPlayerDelegate { @IBOutlet weak var playerView: player? } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) // Reset SDK //licenseKey = access_key let licenseKey = "{access_key}" // Player option (use script code made in the console) let playerOptions = """ { "playlist":[ { "file":"https://CDNdomain/example_video_01.mp4", "poster":"https://CDNdomain/example_video_01.png", } ], "autostart":true, } """ NCPlayer.shared.initialize(licenseKey: licenseKey) NCPlayer.shared.delegate = self // Run playerView?.play(playerOptions) }
3. Event settings
With the Player Event API, you can bind and utilize events that occur in the Video Player Enhancement player. The following describes how to do:
- Check the network status of a device using the
NCPlayerNetworkStatus
method.import NCPlayerSDK ... class ViewController: UIViewController, NCPlayerDelegate{ ... func NCPlayerNetworkStatus(state: String) { // state: satisfied = no problem (ONLINE) // state: unsatisfied = a problem occurs (OFFLINE or Communication failure occurs) // state: requiresConnection = Currently not available, use when connected to the Internet } }
- Check out how to set up the event you want to set up.
Horizontal mode activation event
To trigger an event when the device is switched to horizontal, use the NCPlayerIsLandscape
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
...
func NCPlayerIsLandscape(state: Bool) {
}
}
Screen capture detection event (for iOS)
To trigger an event when capturing screen, use the NCPlayerIsCaptured
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
...
func NCPlayerIsCaptured(state: Bool) {
}
}
OS Screen recording detection event (for iOS)
To trigger an event when recording screen, use the NCPlayerIsRecording
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
...
func NCPlayerIsRecording(state: Bool) {
}
}
TimeUpdate event
To trigger an event when detecting changes in playback time, use the NCPlayerOnTimeUpdate
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
...
func NCPlayerOnTimeUpdate(data: Dictionary<String, Any>?) {
//data = ["duration": 117, "percent": 31.26565391099825, "viewingTime": 37, "currentTime": 37, "sourceType": vod]
}
}
For more information about each property, see timeupdate scipt.
PrevTrack event
To trigger an event when you move to the previous video in the playlist, use the NCPlayerOnPrevTrack
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
...
func NCPlayerOnPrevTrack(data: Dictionary<String, Any>?) {
}
}
For more information about each property, see prevTrack script.
NextTrack event
To trigger an event when you move to the next video in the playlist, use the NCPlayerOnNextTrack
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
...
func NCPlayerOnNextTrack(data: Dictionary<String, Any>?) {
}
}
For more information about each property, see nextTrack script.
Control bar activation event
To trigger an event when you enable/disable control bar in a player, use the NCPlayerOnControlbarActive
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
...
func NCPlayerOnControlbarActive(active: Bool) {
// active: true , false
}
}
Playback event
To trigger an event when playing a video in the player, use the NCPlayerOnPlay
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
...
func NCPlayerOnPlay() {
}
}
Temporary pause event
To trigger an event when pausing a video in the player, use the NCPlayerOnPause
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
...
func NCPlayerOnPause() {
}
}
Playback completion event
To trigger an event when a video is played completely in the player, use the NCPlayerOnEnd
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
...
func NCPlayerOnEnd() {
}
}
Full screen event
By enabling full screen, you can trigger an event and switch to full screen based on device rotation direction.
To trigger an event when enabling full screen for a player, use the NCPlayerOnFullscreen
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
...
// Event that occurs when full screen is off
func NCPlayerOnFullscreenOff() {
}
// Event that occurs when full screen is on
func NCPlayerOnFullscreenOn() {
}
// Classify true/false when full screen in on
func NCPlayerOnFullscreen(state: Bool?) {
}
}
To enable full screen after detecting a button or device rotation direction, use the NCPlayerRequestOrientation
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
var currentOrientationMask: UIInterfaceOrientationMask = .portrait
var currentOrientation: UIInterfaceOrientation = .portrait
// Switch to full screen when horizontally rotating and return when vertically rotated
func NCPlayerRequestOrientation(orientation: String) {
if (orientation == "landscape") {
currentOrientationMask = .landscape
currentOrientation = .landscapeRight
} else {
currentOrientationMask = .portrait
currentOrientation = .portrait
}
applyOrientation(orientation: currentOrientation)
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return currentOrientationMask;
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return currentOrientation;
}
override var prefersStatusBarHidden: Bool {
return currentOrientation.isLandscape
}
}
extension NSLayoutConstraint {
func applyAspectRatio(view: UIView, ratio: CGFloat) -> NSLayoutConstraint {
let newConstraint = NSLayoutConstraint(item: self.firstItem!, attribute: self.firstAttribute, relatedBy: self.relation, toItem: self.secondItem, attribute: self.secondAttribute, multiplier: ratio, constant: self.constant)
view.removeConstraint(self)
view.addConstraint(newConstraint)
view.layoutIfNeeded()
return newConstraint
}
}
}
To enable full screen after detecting device rotation direction, use the NCPlayerIsLandscape
method to set as follows:
import NCPlayerSDK
...
class ViewController: UIViewController, NCPlayerDelegate{
var currentOrientationMask: UIInterfaceOrientationMask = .portrait
var currentOrientation: UIInterfaceOrientation = .portrait
func NCPlayerIsLandscape(state: Bool) {
if state {
currentOrientationMask = .landscape
currentOrientation = UIDevice.current.orientation == .landscapeLeft ? .landscapeRight : .landscapeLeft
}else{
currentOrientationMask = .portrait
currentOrientation = .portrait
}
applyOrientation(orientation: currentOrientation)
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return currentOrientationMask;
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return currentOrientation;
}
override var prefersStatusBarHidden: Bool {
return currentOrientation.isLandscape
}
}
extension NSLayoutConstraint {
func applyAspectRatio(view: UIView, ratio: CGFloat) -> NSLayoutConstraint {
let newConstraint = NSLayoutConstraint(item: self.firstItem!, attribute: self.firstAttribute, relatedBy: self.relation, toItem: self.secondItem, attribute: self.secondAttribute, multiplier: ratio, constant: self.constant)
view.removeConstraint(self)
view.addConstraint(newConstraint)
view.layoutIfNeeded()
return newConstraint
}
}
}