Page 1 of 1

Handling Back

PostPosted: Thu Jun 18, 2015 11:45 am
by edunn_1
I have a question about how to get the back button to quit the app back to the live TV.

Do I map commands to function keydownhandler(e)?

Additionally, when do I use SmartTvA_API.exit(); ?

My need is when back is pressed, I save some data about the current video time code to localstorage, I'm just not sure how to grab the back command.

In the sample video player app, I don't see any mapping of an exit or back command, but on the emulator, I'm able to return to the first page of my two-page app. When I'm sitting on the index file (the first page of the 2 page app) the back button doesn't return me to the TV app menu. I'm confused where and how the back button gets defined.

Thanks so much for your help.

Handling Back

PostPosted: Tue Jun 30, 2015 10:22 am
by edunn_1
I'm sad nobody seems to know the answer to this question.

I see there's this code:
Code: Select all
function processBack()
{
if (myplatform[\"manufacturer\"] == \"LG\")
{
if(window.NetCastBack)
{
window.NetCastBack();
}

}

But I don't understand how or where this actually gets called via button press.

Re: Handling Back

PostPosted: Tue Sep 01, 2015 1:28 am
by aisaia
Hi,

You need to register a 'keydown' event listener:

Code: Select all

window.document.addEventListener("keydown", keyDownHandler, false);

function keyDownHandler(event) {
   switch(event.keyCode) {
      case KEY_LEFT   :  break;
      case KEY_RIGHT : break;
      case KEY_UP       : break;
      case KEY_DOWN  : break;
      case KEY_ENTER : break;
      case KEY_BACK  : processBack(); break;
   
      case KEY_PAUSE : break;
      case KEY_PLAY  : break;
      case KEY_STOP  : break;
      case KEY_RW    : break;
      case KEY_FF    : break;
         
      default: return;
   }
}

function processBack() {
   if (myplatform[\"manufacturer\"] == \"LG\") {/* YOU NEED TO DETERMINE THE PLATFORM */
      if(window.NetCastBack) {
         window.NetCastBack();
         //window.NetCastReturn(KEY_BACK); // <- OR THIS
      }
   }

   // Smart TV Alliance
   if(typeof SmartTvA_API !== undefined) {/* YOU'D EXPECT THIS TO WORK FOR ALL, BUT IT DOES NOT */
      try {
         SmartTvA_API.exit();
      } catch(e) {}
   }
         
   window.close();
   window.history.back();
}



Hope it helps.