Create a player for iOS

Prev Next

Available in Classic and VPC

Applying a player for iOS describes the example for applying and setting Native player for iOS with Video Player Enhancement iOS SDK.

Note

If you implement the examples of iOS SDK, you must use the Standard plan, which requires the following circumstances:

  • Xcode
  • Environment that can communicate externally

Apply player

The following describes how to apply a player:

  1. Run Xcode.
  2. Click the Targets > General menu in the projects to add in order.
  3. In Framework, Libraries, and Embedded Content, add "NCPlayerSDK.xcframework" as Embed & Sign type.
  4. Load NCPlayerSDK into the VC you want to use.
  5. After creating Class, refer to NCPlayerView.
    vpe-example-ios_view
  6. Specify Class of View as PlayerView.
    vpe-example-ios_playerview

Set up player

The following describes how to set up the player:

  1. Apply the following code to reset NCPlayerView Class in VC:

    class PlayerView:NCPlayerView{}
    class ViewController: UIViewController {
        // Connect with view
        @IBOutlet weak var playerView: PlayerView?
    }
    
  2. After creating override func viewDidAppear, apply the following code:

    Note
    • You can call the method after creating NCPlayerView object.
    • Bundle ID must be the same as the app package ID registered in the console.
    var defaultBackground: UIColor? = .white
    func updateBackgroundColor() {
          if UIDevice.current.orientation.isLandscape {
              self.view.backgroundColor = .black
          } else {
              self.view.backgroundColor = defaultBackground
          }
      }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    
        defaultBackground = self.view.backgroundColor
    
        updateBackgroundColor()
    }
    
    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        updateBackgroundColor()
    }
    
    override func viewDidAppear(_ animated: Bool) {
            super.viewDidAppear(animated)
    
            // Reset SDK
            // Enter license key
            let licenseKey = "{your license key}"
    
            // Enter player options (use script code made in the console)
            let playerOptions = """
             {
                "playlist":[
                    {
                        "file":"https://pdeubxscnimo10174288.cdn.ntruss.com/hls/uqyCPUeJ1Ne8ml9OtPsizg__/shorts24/j5IXBfIJ83893893_shorts,1080,720,480,p.mp4.smil/master.m3u8",
                        "poster":"https://nnbkegvqsbcu5297614.cdn.ntruss.com/profile/   202211/083fff831d8904cd9d9c180e5c10be0b.png",
                     "description":{
                            "title":"NAVER Cloud test video1",
                            "created_at":"2022.07.13",
                         "profile_name":"NAVER Cloud",
                            "profile_image":"https://nnbkegvqsbcu5297614.cdn.ntruss.com/profile/202208/d127c8db642716d84b3201f1d152e52a.png"
                        },
                    },
                   {
                       "file":"https://pdeubxscnimo10174288.cdn.ntruss.com/hls/uqyCPUeJ1Ne8ml9OtPsizg__/shorts24/j5IXBfIJ83893893_shorts,1080,720,480,p.mp4.smil/master.m3u8",
                       "poster":"https://nnbkegvqsbcu5297614.cdn.ntruss.com/profile/202211/083fff831d8904cd9d9c180e5c10be0b.png",
                       "description":{
                           "title":"NAVER Cloud test video2",
                           "created_at":"2022.07.13",
                           "profile_name":"NAVER Cloud",
                           "profile_image":"https://nnbkegvqsbcu5297614.cdn.ntruss.com/profile/202208/d127c8db642716d84b3201f1d152e52a.png"
                       },
                   },
                   {
                       "file":"https://pdeubxscnimo10174288.cdn.ntruss.com/hls/uqyCPUeJ1Ne8ml9OtPsizg__/shorts24/j5IXBfIJ83893893_shorts,1080,720,480,p.mp4.smil/master.m3u8",
                       "poster":"https://nnbkegvqsbcu5297614.cdn.ntruss.com/profile/202211/083fff831d8904cd9d9c180e5c10be0b.png",
                       "description":{
                           "title":"NAVER Cloud test video3",
                           "created_at":"2022.07.13",
                           "profile_name":"NAVER Cloud",
                           "profile_image":"https://nnbkegvqsbcu5297614.cdn.ntruss.com/profile/202208/d127c8db642716d84b3201f1d152e52a.png"
                       },
                   }
                ],
                "autostart":true,
                "muted":true,
                "keyboardShortcut":true,
                "controls":true,
                "ui":"pc",
                "controlBtn":{
                    "play":true,
                    "fullscreen":true,
                    "volume":true,
                    "times":true,
                    "pictureInPicture":true,
                    "setting":true,
                },
                "progressBarColor":"#ff0000",
                "controlActiveTime":3000,
                "startMutedInfoNotVisible":false,
                "aspectRatio":"16/9",
                "objectFit":"contain",
                "playRateSetting":[0.5,0.75,1,1.5,2],
                "seekingPreview":true,
                "autoPause":false,
                "repeat":false,
                "touchGestures":true,
                "descriptionNotVisible":false,
                }
    
             """
    
            NCPlayer.shared.initialize(licenseKey: licenseKey)
            NCPlayer.shared.delegate = self
    
            playerView?.play(playerOptions)
        }
    
  3. Create the function after inheriting NCPlayerDelegate from ViewController.
    vpe-example-ios_delegate

  4. Apply the following code to set an event:

        // Network connected or not
    func NCPlayerNetworkStatus(state: String) {
        print("networkStatus: \(state)")
    }
        // Full screen or not
    func NCPlayerOnFullscreenState(state: Bool) {
        print("onFullscreenState: \(state)")
    }
        // Horizontal mode or not
    func NCPlayerIsLandscape(state: Bool) {
        print("isLandscape: \(state)")
    }
    
        // Event that occurs when the current play time changes
    func NCPlayerOnTimeUpdate(data: Dictionary<String, Any>?) {
        if let data = data {
            print("time: ",data)
        }
    }
    
        // Event that occurs when moving to the previous video
    func NCPlayerOnPrevTrack(data: Dictionary<String, Any>?) {
        if let data = data {
            print("NCPlayerOnPrevTrack: ",data)
        }
    }
    
        // Event that occurs when moving to the next video
    func NCPlayerOnNextTrack(data: Dictionary<String, Any>?) {
        if let data = data {
            print("NCPlayerOnNextTrack: ",data)
        }
    }
    
        // To enable or disable a control bar or not
    func NCPlayerOnControlbarActive(active: Bool) {
        print("NCPlayerOnControlbarActive: ",active)
    }
    
        // Event that occurs when the video playback attempt is successful
    func NCPlayerOnPlay() {
        print("NCPlayerOnPlay: play")
    }
    
        // Event that occurs when a video is paused temporarily
    func NCPlayerOnPause() {
        print("NCPlayerOnPause: pause")
    }
    
        // Event that occurs when the playback is completed to the end
    func NCPlayerOnEnd() {
        print("NCPlayerOnEnd: end")
    }
        // Captured or not
    func NCPlayerIsCaptured(state: Bool) {
        print("NCPlayerIsCaptured: \(state)")
    }
        // Recorded or not
    func NCPlayerIsRecording() {
        print("Record")
    }
       // Full screen is off
    func NCPlayerOnFullscreenOff() {
        print("NCPlayerOnFullscreenOff: Off")
    }
        // Full screen is on
    func NCPlayerOnFullscreenOn() {
        print("NCPlayerOnFullscreenOn: On")
    }
        // Full screen is true or false
    func NCPlayerOnFullscreen(state: Bool?) {
        if let state = state {
            print("NCPlayerOnFullscreen: \(state)")
        }
    
    }