Search code examples
javascriptsamsung-smart-tv

Samsung smart tv application using Google API?


I have just started working on Samsung smart tv platform. I am coding a ticker application which utilizes google api for rendering the data. So part of the script is on google. Now to run the dependent functions i have to include

<script lang="javascript" type="text/javascript" src="https://www.google.com/jsapi"></script>

Button control events are handled in a seperate Main.js file as below `

switch(keyCode)
{
    case tvKey.KEY_RETURN:

    case tvKey.KEY_PANEL_RETURN:
        alert("RETURN");
        widgetAPI.sendReturnEvent();
        break;
    case tvKey.KEY_LEFT:
        alert("LEFT");
        break;
    case tvKey.KEY_RIGHT:
        alert("RIGHT");
        break;
    case tvKey.KEY_UP:
        alert("UP");
        break;
    case tvKey.KEY_DOWN:
        alert("DOWN");
        break;
    case tvKey.KEY_ENTER:
    case tvKey.KEY_PANEL_ENTER:
        alert("ENTER");
        break;
    default:
        alert("Unhandled key");
        break;
}`

Now i need to run the function which uses Google API in case of button press event (in Main.js). Trying to do so is giving me the following error

##[JAVASCRIPT ERROR]
##File         : file://localhost/C:\Program%20Files\Samsung\Samsung%20TV%20SDK(3.5.1)\Apps/_temp_20100108_/app/javascript/gfdynamicfeedcontrol.js
##Line No      : 87
##Error Detail : TypeError: google.feeds is undefined

The probable workaround for the situation seems to find out a way to include

<script lang="javascript" type="text/javascript" src="https://www.google.com/jsapi"></script>

in Main.js

Is there a way to do so ?

Any other workaround for the problem ?


Solution

  • If loading an external resource you may have to block your script execution until the file has completely loaded. You can using something like $(document).ready or set a timeout and check to see if a constant defined in the script exists.