For Android
    • PDF

    For Android

    • PDF

    Article Summary

    Available in Classic and VPC

    Android Environment describes how to use Video Player Enhancement Android SDK for Android players and apply players and setting options in the Android environment.

    Note

    To use the Video Player Enhancement SDK for Android, you must use the Standard pricing plan, which requires the following specifications:

    • Minimum specification: API 26 (Oreo 8.0) or later, Gradle 4.2.2 or later
    • Development environment: Android Studio

    Install SDK and configure environment

    The following describes how to install the SDK and add the framework:

    1. Click the environment you are using in the Region menu and the Platform menu on the NAVER Cloud Platform console.
    2. Click Services > Media > Video Player Enhancement.
    3. Click the Video Player Management menu.
    4. Click the [SDK Address] button for the player to download the SDK in the player’s list.
    5. Click the [Android] button in Downloading mobile native SDKs.
      • The zipped files will be downloaded.
    6. Add the downloaded SDK file to the root > app > libs path.
    7. Add to the dependencies of the build.gradle file at the app-level as follows:
      dependencies {
          ...
          implementation files('libs/NCPlayerSDK.aar')
          implementation 'com.google.code.gson:gson:2.10.1'
      }
      

    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 com.sgrsoft.ncp_aos.*
    ...
    class MainActivity : AppCompatActivity() {
        ...
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
            ...
            var delegate = PlayerDelegate()
            NCPlayer.delegate = delegate
    
        }
    }
    

    2. Player settings

    The following describes how to set up the player:

    1. Click the environment you are using in the Region menu and the Platform menu on the NAVER Cloud Platform console.

    2. Click Services > Media > Video Player Enhancement.

    3. Click the Video Player Management menu.

    4. Click the [SDK address] button on the player you want to set up.

    5. When the Player SDK address prompt appears, view the access_key value in the SDK address.
      vpe-ios_key_ko

    6. In Android Studio, create UIView to use NCPlayerView.

    7. Set options for the player.

      import com.sgrsoft.ncp_aos.*
      ...
      class MainActivity : AppCompatActivity() {
          ...
          private lateinit var webView: WebView;
      
          override fun onCreate(savedInstanceState: Bundle?) {
              super.onCreate(savedInstanceState)
              setContentView(R.layout.activity_main)
              ...
      
              webView = findViewById(R.id.webVIew)
      
              // Use registered APPLICATION_ID, only the package ID registered in the console is allowed
              var packageId = BuildConfig.APPLICATION_ID
      
              // licenseKey = access_key
              var licenseKey = "{access_key}" 
      
              // To use screen recording and capture prevention features (true: functional limitation)
              var isScreenCaptureDeny = false
      
              // Create NCPlayerView
              var player = NCPlayerView()
      
              // Connect to NCPlayerView webview
              player.webView = webView
      
              NCPlayer.prefs.setString("appId",packageId)
              NCPlayer.prefs.setString("licenseKey",licenseKey)
              NCPlayer.prefs.setString("isScreenCaptureDeny", isScreenCaptureDeny.toString())
      
              // Player option (use script code made in the console)
              val playerOptions = 
              """
              {
                  "playlist":[
                      {
                          "file":"https://CDNdomain/example_video_01.mp4",
                          "poster":"https://CDNdomain/example_video_01.png",
                      }
                  ],
                  "autostart":true,
              }
      
              """
              // Run
              player.play(playerOptions,this)
          }
      }
      
    8. Write the code to prevent recording as follows:

      import com.sgrsoft.ncp_aos.*
      ...
      class MainActivity : AppCompatActivity() {
          ...
      
          private lateinit var webView: WebView;
          var player = NCPlayerView()
      
          override fun onCreate(savedInstanceState: Bundle?) {
              super.onCreate(savedInstanceState)
              setContentView(R.layout.activity_main)
              ...
              // To use screen recording and capture prevention features (true: functional limitation)
              val isScreenCaptureDeny = false
      
              // Register variables in NCPlayer
              // No change allowed to string value in ""
              NCPlayer.prefs.setString("isScreenCaptureDeny", isScreenCaptureDeny.toString())
          }
      }
      
    9. Write the code to use the Picture in Picture feature as follows:

      override fun onUserLeaveHint() {
      // If you want the horizontal ratio \<example> 16,9
      // If you want the vertical ratio \<example> 9,16
      player.enterPip(this,9,16)
      }
      
    10. To prevent Memory Leak when using webview, write the player unlock code as follows:

      import com.sgrsoft.ncp_aos.*
      ...
      class PlayerDelegate: NCPlayerEventInterface{
      ... 
          player.destroy()
      }
      

    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:

    1. Check the network status of a device using the NCPlayerNetworkStatus method.
      import com.sgrsoft.ncp_aos.*
      ...
      class PlayerDelegate: NCPlayerEventInterface{
          ...
          override fun NCPlayerNetworkStatus(state: String) {
              // state: ONLINE = no problem (ONLINE)
              // state: OFFLINE = a problem occurs (OFFLINE or Communication failure occurs)
          }
      }
      
    2. 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 com.sgrsoft.ncp_aos.*
    ...
    class PlayerDelegate: NCPlayerEventInterface{
        ...
        override fun NCPlayerIsLandscape(state: Boolean) {
        
        }
    }
    

    TimeUpdate event

    To trigger an event when detecting changes in playback time, use the NCPlayerOnTimeUpdate method to set as follows:

    import com.sgrsoft.ncp_aos.*
    ...
    class PlayerDelegate: NCPlayerEventInterface{
        ...
        override fun NCPlayerOnTimeUpdate(data: JSONObject?) {
            // data = {"sourceType":"vod","currentTime":1,"duration":7715,"percent":0.008898181834278056,"viewingTime":1}
        }
    }
    
    Note

    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 com.sgrsoft.ncp_aos.*
    ...
    class PlayerDelegate: NCPlayerEventInterface{
        ...
        override fun NCPlayerOnPrevTrack(data: JSONObject?) {
            // {"file":"","poster":"","description":{"title":"title","created_at":"","profile_name":"string","profile_image":"string"}}
        }
    }
    
    Note

    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 com.sgrsoft.ncp_aos.*
    ...
    class PlayerDelegate: NCPlayerEventInterface{
        ...
        override fun NCPlayerOnNextTrack(data: JSONObject?) {
            // {"file":"","poster":"","description":{"title":"title","created_at":"","profile_name":"string","profile_image":"string"}}
        }
    }
    
    Note

    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 com.sgrsoft.ncp_aos.*
    ...
    class PlayerDelegate: NCPlayerEventInterface{
        ...
        override fun NCPlayerOnControlbarActive(active: JSONObject?) {
            // 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 com.sgrsoft.ncp_aos.*
    ...
    class PlayerDelegate: NCPlayerEventInterface{
        ...
        override fun NCPlayerOnPlay() {
        
        }
    }
    

    Temporary pause event

    To trigger an event when pausing a video in the player, use the NCPlayerOnPause method to set as follows:

    import com.sgrsoft.ncp_aos.*
    ...
    class PlayerDelegate: NCPlayerEventInterface{
        ...
        override fun 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 com.sgrsoft.ncp_aos.*
    ...
    class PlayerDelegate: NCPlayerEventInterface{
        ...
        override fun NCPlayerOnEnd() {
        
        }
    }
    

    Full screen event

    You can trigger an event when switching to full screen and automatically enable full screen when rotating a device.

    Full screen event

    To trigger an event when enabling full screen for a player, use the NCPlayerOnFullscreen method to set as follows:

    import com.sgrsoft.ncp_aos.*
    ...
    class PlayerDelegate: NCPlayerEventInterface{
        ...
        
        val delegate = PlayerDelegate()
        NCPlayer.delegate = delegate
        
        override fun NCPlayerOnFullscreenState(state: Boolean) {
            // fullscreen true / false
        }
        
        // Event that occurs when full screen is off
        override fun NCPlayerOnFullscreenOff() {
        
        }
        
        // Event that occurs when full screen is on
        override fun NCPlayerOnFullscreenOn() {
        
        }
    }
    

    Automatic switching to full screen

    To provide the feature for automatic switching to full screen when rotating a device, configure as follows:

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
    
        if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
        {
            NCPlayer.delegate?.NCPlayerIsLandscape(false)
            player.fullscreenOff()
        }
        else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
        {
            NCPlayer.delegate?.NCPlayerIsLandscape(true)
            player.fullscreenOn()
        }
    }
    

    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.