2

I have a media application for the Amazon Fire tv and tv stick. I have successfully captured the buttons and have customized the events accordingly. Issue arises in the case when some other media app such as pandora is running in the background. When I fastforward,rewind etc in my app , even pandora gets changed in the process.Amazon has declined the app for the same reason.How do I get to set the focus of the remote in the current app only. The following is my code for remote

 @Override
public boolean onKeyDown(int keyCode, KeyEvent event){

    boolean handled = false;
    switch (keyCode){
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_DPAD_LEFT:
            mPlayerView.seek((int)mPlayerView.getPosition()-3000);
            handled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            Log.e("right","pressed");
            mPlayerView.seek((int)mPlayerView.getPosition()+3000);
            handled = true;
            break;
        case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
            mPlayerView.seek((int)mPlayerView.getPosition()+60000);
            handled=true;
            break;
        case KeyEvent.KEYCODE_MEDIA_REWIND:
            mPlayerView.seek((int)mPlayerView.getPosition()-60000);
            handled=true;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            mPlayerView.play();
            handled=true;
            break;
        case KeyEvent.KEYCODE_MENU:
            subtitle=!subtitle;
            if(subsexists){
            if(subtitle) {
                mPlayerView.setCurrentCaptions(1);
                Toast.makeText(this,"Subtitles ON",Toast.LENGTH_LONG).show();
            }
            else {
                mPlayerView.setCurrentCaptions(0);
                Toast.makeText(this,"Subtitles OFF",Toast.LENGTH_LONG).show();
            }
            }
            handled=true;
            break;
    }
    return handled || super.onKeyDown(keyCode, event);
}
aynber
  • 22,380
  • 8
  • 50
  • 63
Sidhanth Sur
  • 303
  • 2
  • 9

1 Answers1

2

See this section of the FireTV Developer FAQ. Specifically you need to implement code to:

you also need to make sure that you gracefully give up control as well if another media player app has the users attention

Offbeatmammal
  • 7,970
  • 2
  • 33
  • 52
  • I read this, but thought it's for people who want their apps to run in the background. Mine being a movie streaming app don't care about it handling the background audio when user quits. The problem is that my remote events is controlling other media applications in the background as they implemented audio manager – Sidhanth Sur Dec 29 '15 at 17:12
  • if you want to control the audio (and the remote) experience then you need to tell Pandora (or whatever currently has focus) to relinquish control. If you don't tell Pandora you're now listening for remote events and providing audio then they will continue to respond. – Offbeatmammal Dec 29 '15 at 17:20
  • hopefully gets you going. wish Amazon would publish a reference sample for their test cases... – Offbeatmammal Dec 29 '15 at 22:13
  • Couldn't get it this way. What we did was to kill any background app that has audio focus. Got approved by Amazon. – Sidhanth Sur Dec 30 '15 at 18:42
  • seems a bit drastic, but if it works who's complaining ;) I didn't have any trouble using the above to obtain audio focus but it was a while ago – Offbeatmammal Dec 30 '15 at 21:29