0

I am attempting to get a very simple HTML/JavaScript application working for SDK 5.0b, the instructions for which are here...

http://samsungtvdev.blogspot.com/2013/04/smamsung-smart-tv-how-to-write-hello.html

I can launch VirtualBox 4.2.16 and see my application in the menu for the emulator. However, when I launch it, the background is black, and I don't see my application. I also see a bunch of warnings in the emulator about 'RegisterType()' and other functions not being available.

I tried posting this on the Samsung SDK forum, but it's pretty dead over there. I also tried the suggestion here, but copying the application manually also doesn't seem to work. Anyone have any ideas on how I can get this working?

Edit: Here is the HTML code. This isn't more than a "hello world" example.

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>HelloWorld</title>

        <!-- TODO : Common API -->
        <script type="text/javascript" language="javascript" src="$MANAGER_WIDGET/Common/API/Widget.js"> </script>
        <script type="text/javascript" language="javascript" src="$MANAGER_WIDGET/Common/API/TVKeyValue.js"> </script>

        <!-- TODO : Javascript code -->
        <script language="javascript" type="text/javascript" src="app/javascript/Main.js"></script>

        <!-- TODO : Style sheets code -->
        <link rel="stylesheet" href="app/stylesheets/Main.css" type="text/css">

        <!-- TODO: Plugins -->

    </head>

    <body onload="Main.onLoad();" onunload="Main.onUnload();">

        <!-- Dummy anchor as focus for key events -->
        <a href="javascript:void(0);" id="anchor" onkeydown="Main.keyDown();"></a>

        <!-- TODO: your code here -->
        <div id="outputDiv"></div>
    </body>
</html>

This is the JavaScript code.

var widgetAPI = new Common.API.Widget();
var tvKey = new Common.API.TVKeyValue();

var Main =
{

};

Main.onLoad = function()
{
    // Enable key event processing
    this.enableKeys();
    widgetAPI.sendReadyEvent();

    alert("App loaded!");
};

Main.onUnload = function()
{

};

Main.enableKeys = function()
{
    document.getElementById("anchor").focus();
};

Main.keyDown = function()
{
    var keyCode = event.keyCode;
    alert("Key pressed: " + keyCode);

    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");
            document.getElementById("outputDiv").innerHTML += "<h1>Hello, World!</h1><br/>";
            break;
        default:
            alert("Unhandled key");
            break;
    }
};

Here are the logs: http://pastebin.com/mZULDGc6

Community
  • 1
  • 1
Brad
  • 2,261
  • 3
  • 22
  • 32

3 Answers3

0

1.) Look for misspellings, typos and missing commas. Samsung Smart TV SDK seems to be very strict with that and since you have no proper console, you don't get any errors if you forget a comma or something

2.) check your HTML/CSS

Maybe you should post your code so I can have a closer look.

EDIT: You forgot to add the scripts in your HTML head. You have to add every script file that you use in your project, such as Main.js. That would be

<script language="javascript" type="text/javascript" src="app/javascript/Main.js"></script>

and also all Samsung SmartTV API script files that are required.

  • Added - sorry it took so long to respond. The code is very simple. I'm not sure what I did wrong. – Brad Jan 19 '14 at 15:27
  • OK, I'm an idiot. I put the wrong HTML code into the question - I've fixed that now. – Brad Jan 29 '14 at 03:27
0

First what i see, you forgot "anchor" tag in html.

<a href="javascript:void(0);" id="anchor" onkeydown="Main.keyDown();"></a>

Not included external JS files in html page, and standard smart tv sdk files:

<script type="text/javascript" language="javascript" src="$MANAGER_WIDGET/Common/API/Widget.js"> </script>
<script type="text/javascript" language="javascript" src="$MANAGER_WIDGET/Common/API/TVKeyValue.js"> </script>

Then add

<body onload="Main.onLoad();" onunload="Main.onUnload();">

Are you sure that images loaded? Print it in console. Why div block position inside canvas, move it outside. I think that code started with js error, so you don't see anything. Be more careful.

Ilya Zaytsev
  • 1,055
  • 1
  • 8
  • 12
  • Yeah, it has something to do with the fact that I pasted the wrong code into the question and somehow missed it. Sorry. – Brad Jan 29 '14 at 03:27
0

I had same issue and fixed it by adding background: red; for body tag in css.