/**************************************************************************/ /* /* IRClient.java -- IR remote control client for NetStereo /* Copyright (C) 2001 Bjorn Bringert (bjorn@mumblebee.com) /* /* This program is free software; you can redistribute it and/or /* modify it under the terms of the GNU General Public License /* as published by the Free Software Foundation; either version 2 /* of the License, or (at your option) any later version. /* /* This program is distributed in the hope that it will be useful, /* but WITHOUT ANY WARRANTY; without even the implied warranty of /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /* GNU General Public License for more details. /* /* You should have received a copy of the GNU General Public License /* along with this program; if not, write to the Free Software /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /* /**************************************************************************/ import java.util.*; import java.io.*; import org.lirc.*; import org.lirc.util.*; /** A SteroClient that takes input from an IR remote control by connecting to the LIRC daemon. @author Bjorn Bringert bjorn@mumblebee.com */ public class IRClient extends StereoClient{ private static final String CONFIG_FILE = "IRClient.lirc"; private SimpleLIRCClient irclient; public IRClient() throws LIRCException, FileNotFoundException, IOException{ super(); irclient = new SimpleLIRCClient(CONFIG_FILE); ioThread.start(); irclient.addIRActionListener(new IRListener()); } public void setError(String error){ System.err.println(error); } public void doCommand(String command){ if (command.equals("prev")){ ioHandler.sendPlay(currentPlaylistIndex - 1); }else if (command.equals("next")){ ioHandler.sendPlay(currentPlaylistIndex + 1); }else if (command.equals("rew")){ ioHandler.sendSkipBack(); }else if (command.equals("ff")){ ioHandler.sendSkipForward(); }else if (command.equals("play") || command.equals("pause")){ if (playState == PS_STOPPED){ ioHandler.sendPlay(currentPlaylistIndex); }else if (playState == PS_PLAYING){ ioHandler.sendPause(); }else if (playState == PS_PAUSED){ ioHandler.sendPause(); } }else if (command.equals("stop")){ // playState will be changed when we get the acknowledgement // message back from the server. ioHandler.sendStop(); }else if (command.equals("exit")){ System.exit(0); }else{ System.err.println("Unknown command: " + command); } } private class IRListener implements IRActionListener{ public void action(String command){ doCommand(command); } } public static void main(String args[]){ try{ new IRClient(); }catch (FileNotFoundException ex){ System.err.println(ex.toString()); }catch (IOException ex){ System.err.println(ex.toString()); }catch (LIRCException ex){ System.err.println(ex.toString()); } } }