Admira API HTML5 content

Admira API content HTML5 is the service available to be able to communicate from an HTML content to the Admira player via Javascript. The basic functions of said API are described below.

In order to use the functionalities of Admira API Content HTML5, it is necessary to have the script, provided by Admira.

Once added as an attachment and included in the main HTML, it can be invoked as follows:

<script>
var api_obj = null;

function on_load(){
    api_obj = new admira_api_content();
    api_obj.onReady = function(){
        console.log(«Ready !»);
    };
    api_obj.onStart = function(){
        console.log(«Start !»);
    };
}
</script>
<body onLoad=”on_load();”>

Events

The basic API Content events are explained here.

  • onReady: occurs when the player has successfully preloaded the HTML content, that is, the HTML has been loaded into the iFrame. At this point the iFrame is still DISPLAY:NONE

  • onStart: occurs when the player puts the content in “PLAY”. Any animation or rendering of elements should start here. At this point the iFrame is still in DISPLAY:INLINE

Features

API content also allows you to send messages to the HTML5 player to indicate different actions to perform:

  • API_DURATION: Change the duration of the content being played

  • API_FINISH: Ends the content being played

  • API_CONDITION: Write a condition to be read later by the player with the capabilities of Conditional Playlist and Conditional Triggers

  • API_WRITE_FILE: Allows writing text data to a file locally

  • API_READ_FILE: Allows you to read a local text file

Note

These features are constantly being developed and improved. For any question, do not hesitate to report to soporte@admira.com.

Note

For app versions lower than z19.05.30, when you want to get the player id, you need to put the call inside onStrat. For versions later than z19.05.30, this included, it can be put inside onReady. Below is an example of how the player id should be requested in both cases.

Application version prior to z19.05.30

my_api.onReady = function(){
    console.log("Ready !”);
};

my_api.onStart = function(){

console.log(“onStart”);

my_api.send("api_command",{command:my_api.API_PLAYER_INFO,params:{'callback':"onGetInfo"}});

};

Application version equal to or later than z19.05.30

my_api.onReady = function(){
    console.log("Ready !”);

    my_api.send("api_command",{
        command:my_api.API_PLAYER_INFO,params:{
        'callback':"onGetInfo"
            }
        });
    };

    my_api.onStart = function(){

    console.log(“onStart”);
};

Examples of functions

# API_DURATION:

api_obj.send("api_command",{
    command:api_obj.API_DURATION,
    params: {
        duration:30
    }
});

→ It will change the duration, where 30 is the number of seconds from the time of the API call.

# API_FINISH:

api_obj.send("api_command",{
    command:api_obj.API_FINISH
});

→ It will end the content immediately.

# API_CONDITION:

var condition_object = {
    'id':01,
    'filename':internet_connected.xml’,
    'value':1,
    ‘write’:true
};

api_obj.send("api_command",{
    command:api_obj.API_CONDITION,
    params:condition_object
});

→ It will write the value of the condition for “Internet Connected”.

# API_WRITE_FILE:

var file_object = {
    'path': ‘./log’,
    'filename':hello.txt’,
    'text':’ Hello World !
};

api_obj.send("api_command",{
    command:api_obj.API_WRITE_FILE,
    params:file_object
});

→ Will write “Hello World!” to ./content/hello.txt

# API_READ_FILE:

function onFileReadComplete(data){
    console.log("HTML onFileReadComplete data : "+data);
}

var file_object = {
    'path': ‘./log’,
    'filename':hello.txt’,
    'callback': ‘onFileReadComplete’
};

api_obj.send("api_command",{
    command:api_obj.API_READ_FILE,
    params:file_object
});

→ It will read ./content/hello.txt and send the result to the callback : onFileReadComplete

# API_PLAYER_INFO:
**Ejemplo completo obtener player_id y usarlo (versiones app inferiores a z19.05.30)

<script>

my_api = new admira_api_content();

var started = false;
var playerId = 0;

if (typeof(Storage) !== "undefined") {
    playerId = localStorage.getItem("playerID");
    myFunction(playerId);
}

if(playerId == 0){
    //Cuando inicia el player (Carga el HTML)
    my_api.onReady = function () {
        setTimeout(function(){my_api.onStart()},time);
    };

    //Cuando emite el HTML
    my_api.onStart = function () {
        clearTimeout(time)
        if(!started){
            my_api.send("api_command", { 
                command: my_api.API_PLAYER_INFO, params: { 'callback': "onGetInfo" 
                } 
            });
        }
    started = true;
    };
    
    my_api.onEvent = function (e) {
        if (started) {
         if (e.action == my_api.API_PLAYER_INFO) {
                if (typeof (e.msg.callback) !== "undefined") {
                    eval(e.msg.callback)(e.msg.data);
                }
            }
        }
    };
}


function onGetInfo(data) {
    try {
        if (data) {
            if (data.PlayerController && data.PlayerController.player_id) {
                playerId = data.PlayerController.player_id;
                localStorage.setItem("playerID", playerId);
                myFunction(playerId);
            }
        }
    }
    catch (e) {
        document.getElementById("contenedor").innerHTML = e;
    }
};

</script>
# API_PLAYER_INFO:
**Ejemplo completo obtener player_id y usarlo (versiones app iguales o superiores a z19.05.30)

<script>

my_api = new admira_api_content();

var started = false;
var playerId = 0;
var time = 2000;

if (typeof(Storage) !== "undefined") {
    playerId = localStorage.getItem("playerID");
    myFunction(playerId);</p>
}

if(playerId == 0){
    //Cuando inicia el player (Carga el HTML)
    my_api.onReady = function () {
        my_api.send("api_command", { 
            command: my_api.API_PLAYER_INFO, params: { 
                'callback': "onGetInfo" 
            }
        });
    };

    //Cuando emite el HTML
    my_api.onStart = function () {
        started = true;
    };
    my_api.onEvent = function (e) {
        if (started) {
            if (e.action == my_api.API_PLAYER_INFO) {
                if (typeof (e.msg.callback) !== "undefined") {
                    eval(e.msg.callback)(e.msg.data);
                }
            }
        }
    };
}

function onGetInfo(data) {
    try {
        if (data) {
            if (data.PlayerController && data.PlayerController.player_id) {
                playerId = data.PlayerController.player_id;
                localStorage.setItem("playerID", playerId);
                myFunction(playerId);
            }
        }
    }
    catch (e) {
        document.getElementById("contenedor").innerHTML = e;
    }
};
</script>

Last updated