简体   繁体   中英

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

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');
}

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM