no i have 3 screens having images and texts. when i press play button from sc1 that is full screen not a sidebar screen then i will face the media player. and the play button to play video will be on screen3. at any moment and from screen1, screen2 when i press the play button from remote it will start to play the video that is last time i played. i don't want to play video with remote play button. it will only play after pressing play button from screen3. i think you got my point.
in short i want to disable the remote play button. can i do this?
Thanks.
There are two ways you can disable the remote control buttons. The first is global, the second is specific to the fullscreen view where you don't want the video to play (i.e., any fullscreen other than the one that will play your video). Each one is the same: you subscribe to a mediaplayer event, listen for specific key codes and then prevent the default behavior from occurring (playing the video).
The first method is to subscribe the entire widget to the mediaplayer. You'd put this code in init.js:
CODE
(function (event) {
if (KONtx.application.getCurrentViewId() !== "view-mediaplayer") {
switch (event.type) {
case "onRemoteKeyPress":
if ($contains(event.payload.keyCode, [19, 413, 412, 415, 417])) {
event.preventDefault();
}
break;
}
}
}.subscribeTo(KONtx.mediaplayer, "onRemoteKeyPress"));
Hopefully, this code is self-explanatory. You subscribe to the mediaplayer's onRemoteKeyPress event. In the listener, you must first check the current view id to make sure that you're not currently in the mediaplayer view (for obvious reasons you don't want to block key codes in your mediaplayer view). Then, it checks the event type and the key code. If the key code is one of those sent when the remote control play, pause, stop, etc. is pressed, then prevent the default mediaplayer behavior, which is to either play, pause, stop, etc. the video.
By the way, I took the key codes from the
mediaplayer source code. Also, look at line 372 in that file, you'll see where the onRemoteKeyPress event is fired by the mediaplayer and how calling preventDefault() in your listener (that is, returning false) doesn't run the code in the conditional that is the mediaplayer's usual path of playing a video (or stopping, pausing, etc.).
Ok, so here's the bad news; due to a known bug, this solution may not work because the current view id is being set incorrectly in the application class. This bug has been fixed, but most devices don't have the framework fix yet.
So, the second way to fix this is to subscribe to the mediaplayer in every fullscreen view where video shouldn't be played. This may actually not be too bad, as most developers only have one fullscreen view in their widget anyway. You'd subscribe to it in the updateView and unsubscribe from it in the hideView. It's VERY important that you remember to unsubscribe from it or the remote control keys will be disabled even on your mediaplayer view since the mediaplayer is a singleton and thus isn't bound to any view.
Tested on 2010 Samsung.
By the way, thanks for finding this bug.