View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.util.launcher;
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.net.URL;
25  
26  /***
27   * Provides the default implements for the {@link Player} interface.
28   */
29  public class DefaultPlayer extends DefaultLauncher implements Player
30  {
31  
32      //--- Constant(s) ---
33  
34      //--- Data field(s) ---
35  
36      /***
37       * The player process.
38       */
39      protected Process player;
40  
41      //--- Constructor(s) ---
42  
43      public DefaultPlayer(String key, String name, String command)
44      {
45  		super(key, name, command);
46      }
47  
48      //--- Method(s) ---
49  
50      /***
51       * Returns true for mp3 files.
52       */
53      public boolean canPlay(File file)
54      {
55  		return file.isDirectory() 
56  			|| file.getName().toLowerCase().endsWith(".mp3");
57      }
58  
59      /***
60       * Executes {@link #getCommand()}, passing <code>file</code> as an
61       * argument.  
62       */
63      public void enqueue(File file) throws IOException
64      {
65  		String args[] = {
66  			getCommand(), file.getAbsolutePath()
67  		};
68  		player = Runtime.getRuntime().exec(args);
69      }
70  
71      /***
72       * Calls {@link #stop()} and {@link #enqueue(File)}.
73       */
74      public void open(File file) throws IOException
75      {
76  		stop();
77  		enqueue(file);
78      }
79  
80      /***
81       * Executes {@link #getCommand()}.
82       */
83      public void start() throws IOException
84      {
85  		stop();
86  
87  		String args[] = {
88  			getCommand()
89  		};
90  		player = Runtime.getRuntime().exec(args);
91      }
92  
93      /***
94       * Calls <code>destory()</code> on the player process, if running.
95       *
96       * @return always returns true
97       */
98      public void stop()
99      {
100 		if (player != null) {
101 			player.destroy();
102 			player = null;
103 		}
104     }
105 
106 	/*
107 	 * FIX: implement
108 	 */
109 	public void open(URL url) throws IOException 
110 	{
111 	}
112 
113 }