1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
33
34
35
36 /***
37 * The player process.
38 */
39 protected Process player;
40
41
42
43 public DefaultPlayer(String key, String name, String command)
44 {
45 super(key, name, command);
46 }
47
48
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
108
109 public void open(URL url) throws IOException
110 {
111 }
112
113 }