Handling Back

Handling Back

Postby edunn_1 » Thu Jun 18, 2015 11:45 am

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.
edunn_1
 
Posts: 15
Joined: Mon Jul 27, 2015 12:50 am

Handling Back

Postby edunn_1 » Tue Jun 30, 2015 10:22 am

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.
edunn_1
 
Posts: 15
Joined: Mon Jul 27, 2015 12:50 am

Re: Handling Back

Postby aisaia » Tue Sep 01, 2015 1:28 am

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.
aisaia
 
Posts: 2
Joined: Mon May 12, 2014 6:52 am


Return to App development questions



cron