How can I check if Samsung Smart TV has Internet connection?

1.2k views Asked by At

I need to know if an Internet connection is available before playing a video. How can I get it?

var url = 'http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4';
//url not found (no Internet)
player.Play(url);

Now this code working wrong. Player start play but we have not internet. How can I be sure that I have a connection to the internet?

//pseudo code
if (player.checkInternet){
 player.Play(url);
}else{
 alert('Error');
}
3

There are 3 answers

1
Frederik.L On

You can check the connection status with:

if (navigator.onLine) {
    player.Play(url);
} else {
    alert('Error');
}

However, this method may have compatibility issues with some browsers. See: Browser compatibility

0
imkrisna On

To check the connectivity of HTTP you can use this following function: http://samsungdforum.com/Guide/ref00011/deviceapi_network_checkhttp.html

But if for the player, it has some callback functions to handle network error, visit the documentation of player object and see onConnectionFailed, onStreamNotFound, etc http://samsungdforum.com/Guide/ref00014/sef_plugin_player.html

1
abhi On

I am using this javascript function to check the network on samsung Tv

Main.CheckConnection = function () {
    //  if(gKeyValues.IsOnTV){
    //  Main.Print("Production environment-------");
    /* For Production Environment */
    var physicalConnection = 0,
    httpStatus = 0;
    var currentInterface = networkPlugin.GetActiveType();
    // If no active connection.
    if (currentInterface == -1) {   //wired=1,wireless=0,no connection=-1
        return false;
    }
    // Check physical connection of current interface.
    physicalConnection = networkPlugin.CheckPhysicalConnection(currentInterface);
    //  Main.Print("Network Status: " + physicalConnection);

    // If not connected or error.
    if (physicalConnection != 1) {
        //Main.okDialog_Init("Message");
        Main.Print("Network disconnected");
        //  Main.IsNetworkActive = false;
        return false;
    }
    // Check HTTP transport.
    httpStatus = networkPlugin.CheckHTTP(currentInterface);
    // If HTTP is not avaliable.
    if (httpStatus != 1) {
        alert("Network disconnected");
        Main.IsNetworkActive = false;
        return false;
    }
    Main.IsNetworkActive = true;
    return true;
    //  }
};

And include this plugin in your HTML page

<object id="pluginObjectNetwork" border=0 classid="clsid:SAMSUNG-INFOLINK-NETWORK" style="width: 0px; height: 0px;"></object>

Please Modify this function according to your requirement this function tackles all the Network and internet related issues in samsun