1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.xnap.util.launcher;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.lang.reflect.Method;
29 import java.net.URL;
30
31 import org.xnap.XNap;
32
33 /***
34 * JMF 2.1-based MP3 audio player. Note that this class
35 * uses nothing but reflection to run the JMF code so that
36 * this class can be loaded without dependencies on the
37 * JMF jar being installed on the user's system.
38 *
39 * @see <A HREF="http://java.sun.com/products/java-media/jmf/index.html">JMF</A>
40 */
41 public class JMFPlayer extends DefaultPlayer
42 {
43
44
45
46
47
48 private Object player = null;
49
50
51
52 public JMFPlayer()
53 {
54 super("jmf", XNap.tr("Java Media Player"), "");
55 }
56
57
58
59 public boolean isEditable()
60 {
61 return false;
62 }
63
64 public boolean isEnabled()
65 {
66 try {
67 Class.forName("javax.media.Manager");
68 }
69 catch (Throwable t) {
70 return false;
71 }
72
73 return true;
74 }
75
76 public void enqueue(File file) throws IOException
77 {
78 stop();
79
80 URL url = file.toURL();
81 try {
82 Class m = Class.forName("javax.media.Manager");
83 Method meth = m.getMethod("createRealizedPlayer",
84 new Class[] { url.getClass() });
85
86
87 Object o = meth.invoke(null, new Object[] {url});
88
89
90 o.getClass().getMethod("start", null).invoke(o, null);
91
92 player = o;
93 }
94 catch (Exception e) {
95 throw new IOException(XNap.tr("Could not instanciate class."));
96 }
97 }
98
99 /***
100 * Does nothing.
101 */
102 public void start() throws IOException
103 {
104 }
105
106 public void stop()
107 {
108 if (player != null) {
109 try {
110
111 Object o = player;
112 o.getClass().getMethod("stop", null).invoke(o, null);
113 o.getClass().getMethod("close", null).invoke(o, null);
114 o.getClass().getMethod("deallocate", null).invoke(o, null);
115 player = null;
116 }
117 catch (Exception ex) {
118 }
119 }
120 }
121
122 }