[Youtube Video] Getting TV Channel Details with the Samsung Smart TV Web API
The Samsung Smart TV Web API provides powerful tools for accessing live TV channel data directly within your app. This tutorial walks through the three main approaches to retrieving channel information using the TVChannel object — from getting the currently tuned channel to scanning the full channel list.
Setting Up the TVChannel Object
Before you can retrieve any channel data, you need to include the Samsung Smart TV Web API JavaScript file in your HTML5 project. Once the script is included, you gain access to the TVChannel module. In your JavaScript file, obtain a reference to the channel object, which will be the gateway to all channel-related functions. Keep in mind that channel APIs only work on a real TV — the emulator does not support live channel data.
Getting the Current Channel
To fetch the channel that is currently being broadcast on the TV, use tvChannel.getCurrentChannel() and pass window ID 0, which represents the default TV input source. The function returns a ChannelInfo object packed with useful properties:
- PTC (physical transmission channel)
- Major and minor channel numbers
- Source ID and LCN (logical channel number)
- Program number and transfer stream ID
- Service name and channel name
You can log whichever properties you need for your use case. The tutorial demonstrates printing the most commonly used fields such as the major channel number and channel name.
Scanning the Full Channel List
To retrieve every channel available from the provider, use tvChannel.getChannelList(). This function accepts a success callback, a failure callback, a scan mode, and a channel range. The scan mode controls which type of channels are included in the scan. The four available scan modes are:
- NavigatorModeAll — scans all channels regardless of type
- NavigatorModeAnalog — scans only analog channels
- NavigatorModeDigital — scans only digital channels
- NavigatorModeFavorite — scans only channels in the favorites list
The success callback receives an array of ChannelInfo objects, one for each channel found. You can iterate over the array using a for loop and read any property from each object — the tutorial uses channelName as an example. If the scan fails for any reason, the failure callback provides an error object you can log for debugging.
Finding a Channel by ID
If you already know the major and minor channel numbers, you can retrieve information for a specific channel — even one that is not currently playing — using tvChannel.findChannel(). Pass the major channel ID, the minor channel ID, a success callback, and a failure callback. The success callback returns a single ChannelInfo object for the matching channel.
An important note: channel numbers are not universal. The number assigned to a given channel varies by provider, so treat them as provider-specific identifiers rather than fixed constants.
Practical Considerations
All three approaches give you a rich set of channel properties you can use for building guide applications, parental controls, channel-switching logic, or any feature that depends on knowing what is on the TV. The key distinction between the methods is scope:
- Use
getCurrentChannel()when you only need data about what is on screen right now. - Use
getChannelList()when you need to present or process the entire lineup. - Use
findChannel()when you know a specific channel ID and want its details without scanning.
Wrapping Up
Channel data access is a foundational capability for any Samsung Smart TV application that interacts with live television. Watch the full video tutorial to see the complete code walkthrough, including how all three functions are wired together inside a single demo app.