Getting Device type information from Samsung Smart TV

Samsung Smart TV

In this article, we are going to discuss on how to get the current device type in a Samsung Smart TV environment programmatically. Currently I am using Samsung Smart TV SDK 5.1 version and a virtual box based emulator for testing. Before starting with the development process, let us think of why we need to get the current device type and associated properties in our Samsung Smart TV application.

Why do we need to identify the device?

Samsung Smart TV SDK helps the developer to develop applications for the Samsung Smart TV environment run time. This run time is found on the Samsung environments ranging from Smart TV, Large Monitors to Blu-Ray players. Identification of device properties is essential in taking key decisions during the initialization of the application. For a simple example the volume control functions of TV will be different when compared to the ones found in the Blu-Ray player. So the detection code will detect the type of the identified device and then take necessary actions based on the type of the device.

What do we need to get started?

I am currently using the Samsung Smart TV SDK 5.1 version and the associated virtual box image. We also need the virtualbox software to run the VirtualBox machine image. I have developed a video tutorial on setting up the sdk and running a sample application. Please take a look at the below video tutorial on how to set up the development environment and running a sample application

Including the necessary libraries

The  one and the only library included for getting the TV functionality is the webapis library. This is a default library included along with the Samsung Smart TV SDK. The library can be included as follows

<script type="text/javascript" language="javascript" src="$MANAGER_WIDGET/Common/webapi/1.0/webapis.js"></script>

Once this library is included, we will get a global object called webapis in our code. We can use this object to call the other methods provided by this library.



Calling the necessary functions

Once the library is included we can call the necessary functions that suit our requirements. Our current requirement is to get the TV information. For that we are going to call the following function.

webapis.tv.info.getProduct()

On calling this function, this will return three constants based on the type of device in which the current code is running. The following are the device types that are returned by this function call.

  • 0 – PL_TV_PRODUCT_TYPE_TV
  • 1 – PL_TV_PRODUCT_TYPE_MONITOR
  • 2 – PL_TV_PRODUCT_TYPE_BD

Each return value indicates a constant that identifies the type of device. The first one being direct TV, the second one being a computer monitor or any other monitor, the third one being a blue ray player or a channel recorder. Now we have identified the type of the device that is currently running the Smart TV application. Running this code piece on the emulator during development period will always return as TV. The following is a code snippet that displays the type of device on the screen based on the detected device type from the code.

Main.detectDeviceType = function () {
	alert('The device type is ' + webapis.tv.info.getProduct());
};

The above function needs to be called from the inside the init function. After pasting the above code, the following output will be shown on the screen. The message shows the type of the detected device on the screen.

Conclusion

In the current tutorial, we have went through steps on getting the device type information using the webapis in Samsung Smart TV platform.  The webapis library can do further. We will look into further details and functionalities in the future articles.




No Comments


You can leave the first : )



Leave a Reply

Your email address will not be published. Required fields are marked *