--- title: "Player integration" slug: "player-integration" updated: 2023-08-22T11:00:59Z published: 2023-08-22T11:00:59Z canonical: "docs.viewlift.com/player-integration" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.viewlift.com/llms.txt > Use this file to discover all available pages before exploring further. # Player integration Developers can interact with the Player SDK by using the VLPlayer class. Add VLPlayer view in your layout xml (or you can create it by code providing all the needed UI parameters). Example: ```custom ``` Now you can simply initialize the VLPlayer Android SDK with a valid ViewLift Token, a ViewLift video ID, along with any optional parameters. At first, declare VLPlayer instance, token, and video Id. ```custom private VLPlayer vlPlayer; public static String vlToken = "enter-viewlift-token"; private static String videoID = "enter-viewlift-video-id" ; ``` Then initialise the player by finding the player view and calling init() method on it . init() method initialises SDK object & allows your code to add configurations to player. //set the VLPlayer to the appropriate view vlPlayer = findViewById(R.id.sampleVideoPlayer); vlPlayer.init(); ```custom //set the VLPlayer to the appropriate view vlPlayer = findViewById(R.id.sampleVideoPlayer); vlPlayer.init(); ``` Set optional parameters for the player. ```custom //set any optional parameters OptionalPlayerParams optionalPlayerParams = new OptionalPlayerParams(); optionalPlayerParams.setAdUrl(adUrl); optionalPlayerParams.setShowThumbImage(true); ``` Now call method setSource to set your video to player. setSource needs to be initialized with: - Valid ViewLift Token - A ViewLift video ID - Video Player Tag - String value for tagging video player instance - this tag will come with every event to identify the instance of player - OptionalPlayerParams – Will have optional parameters like thumbnail image show or ad URL. ```custom vlPlayer.setSource(vlToken, videoID, “tag1”, optionalPlayerParams); ``` init & setSource methods needs to be used for every new instance of player. Having separate init methods for each player makes sure we can have different configs for each player instance. Next, in your video player activity class paste this: ```custom @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == VLPlayerActivity.LAST_PLAY_POSITION) { seekPosition = data.getExtras().getLong(VLPlayerActivity.VL_LAST_PLAY_POSITION, 0); int cc_button_pref_name_id = getResources().getIdentifier("cc_button_pref_name","string", getPackageName()); SharedPreferences ccPrefs = getSharedPreferences(getString(cc_button_pref_name_id), MODE_PRIVATE); int cc_button_key_id = getResources().getIdentifier("cc_button_key","string", getPackageName()); boolean isClosedCaptionEnabled = ccPrefs.getBoolean(getString(cc_button_key_id), false); if (this instanceof VLPlayerVideoEventListener) { VLPlayerVideoEventListener vlPlayerVideoEventListener = (VLPlayerVideoEventListener) this; vlPlayerVideoEventListener.onFullscreenChange(seekPosition, false); } vlPlayer.setCcButton(isClosedCaptionEnabled); int current_video_position_id = getResources().getIdentifier("current_video_position","string", getPackageName()); playlistPosition = data.getExtras().getInt(this.getString(current_video_position_id), 0); if (playlistPosition > 0 && playlistPosition != vlPlayer.currentVideoPosition) { vlPlayer.playVideoInPlaylist(playlistPosition); startNewVideo = true; } else { vlPlayer.pause(); vlPlayer.seekTo(seekPosition); } } } ``` Lastly, ensure that the versions of com.android.support:* libraries match between your app and inside the VLPlayer SDK. Notes Sometimes, lint may report an error when you try to access resources from the library using **com.vl.viewlift.player.R**. However, the project will still work fine if you run it To solve this lint error, you can use the following code: **getResources().getIdentifier(String name, String defType, String defPackage)** Where: **name** is the name of the resource. **defType** is the type of resource. **defPackage** is the package name of your app. For example, to access a string resource, the syntax would be : **getResources().getIdentifier("cc_button_pref_name","string", getPackageName())** Similarly, to access a layout resource, you would use the following syntax: **getResources().getIdentifier("vl_playback_control_view","layout", getPackageName());** And for an image resource, please use the following syntax: **getResources().getIdentifier("ic_fullscreen_24dp","drawable", getPackageName())**