top

Volume control policy

Published 2014-10-27 | (Compatible with SDK 5.0,5.1 and 2014 models)

Official guidelines how to implement your own Volume OSD

Source Files

Note

The files needed for the sample application are here.

General policy

This is the volume usage/control guide for Samsung Apps that use the audio or video player. If you don’t follow this guide, your application may not be able to control the HDMI-CEC device or an external receiver.

Note

The recommended way is to use the native Samsung platform Volume OSD. The native Volume OSD has a dedicated API which can easily be used in your applications.

Implementation example

Below, there is some sample code on how to implement such functionalities.

In index.html file:

<script type="text/javascript" src="$CAPH/1.0.0/caph-level1-unified.min.js"></script>
<script type="text/javascript" language="javascript" src="$MANAGER_WIDGET/Common/webapi/1.0/webapis.js"></script>
<script type="text/javascript" language="javascript" src="$MANAGER_WIDGET/Common/webapi/1.0/deviceapis.js"></script>

in the AudioFunctions.js file:

var PL_TV_PRODUCT_TYPE_BD = 2;
var productType  = null;

Audio_Functions.volumeUp = function () {
    productType = deviceapis.tv.info.getProduct();
    if (productType == PL_TV_PRODUCT_TYPE_BD) {
            return;
    } else {
            try {
                webapis.audiocontrol.setVolumeUp();
                console.log("Volume is up");
            } catch(error) {
                console.log(error.name);
            }
    }
};

Audio_Functions.volumeDown = function () {
    productType = deviceapis.tv.info.getProduct();
    if (productType == PL_TV_PRODUCT_TYPE_BD) {
            return;
    } else {
            try {
                webapis.audiocontrol.setVolumeDown();
                console.log("Volume is down");
            } catch(error) {
                console.log(error.name);
            }
    }
};

Audio_Functions.volumeMute = function () {
    productType = deviceapis.tv.info.getProduct();
    if (productType == PL_TV_PRODUCT_TYPE_BD) {
            return;
    } else {
            try {
                if(webapis.audiocontrol.getMute()) {
                    webapis.audiocontrol.setMute(false);
                    console.log("TV is on mute");
                } else {
                    webapis.audiocontrol.setMute(true);
                    console.log("TV is not on mute");
                };
            } catch(error) {
                console.log(error.name);
            }
    }
};