1. Help
  2. Developer Documentation & APIs
  3. How to dynamically add and remove videos from a playlist using API

How to dynamically add and remove videos from a playlist using API

Welcome to Cincopa’s help center! It’s an easy to use, step-by-step process to help you get the most out of your Cincopa account and your Tube. Below is the steps on how to switch to another video on Cincopa’s Video Player API.

Many of Cincopa’s most powerful video player features are available through our API. Developers can offer users a flexible, intuitive control of video content using a simple set of HTML events.

Here you can see a live example of how our API player controls work

How to Add Cincopa Video Player Buttons Through the API

You will also need to add the corresponding PlayerAPI function:

function playerAPI() {
    var galleryWrapID = 'playerID';
    if (cincopa && cincopa.getGalleryById(galleryWrapID) && cincopa.getGalleryById(galleryWrapID).playerAPI) {
        return cincopa.getGalleryById(galleryWrapID).playerAPI;
    } else {
        return false;
    }
}

Here you can find some instruction how to add/remove video to playlist. Its already possible to use combination of this APIs. Check it in action in this example codepen.

1. Add Video to Playlist

You can add video to playlist using the following scripts:

Function: 

function addVideo(rid) { 
    galleryGlobal.get_asset_meta(rid, function (data) {
        playerAPI().playlistAppend(data)
    });
    return false
}

2. Remove Video from Playlist

Function: 

function removeVideo(index) {
    playerAPI() && playerAPI().playlistRemove(index);
}

3. Go to Another Video from the Playlist

You can go to video from playlist using the following scripts:

Function: 

function goTo(index) {
    playerAPI() && playerAPI().goTo(index);
}

4. Switch to Another Video Chapter from the Playlist

You can add or remove video and go to chapter video from playlist using the following scripts:

Function: 

function switchVideo(rid, chapter, time) {
    galleryGlobal.get_asset_meta(rid, function (data) {
        playerAPI().playlistAppend(data);
        removeVideo(1);
        playerAPI().goTo(1, function () {
        if (chapter)
            playerAPI().goToChapter(chapter);
        else if (time)
            playerAPI().setCurrentTime(time);
        });
    });
}


Note: goTo API has second param callback that fired when player already loaded reuqested video.

Was this article helpful?