1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package javax.microedition.media;
24
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.util.Vector;
28
29 import org.microemu.midp.media.audio.PCTone;
30
31 public final class Manager
32 {
33
34 public static final String TONE_DEVICE_LOCATOR = "device://tone";
35 static Vector vMedia = null;
36
37 public static String[] getSupportedContentTypes(String protocol)
38 {
39
40 return new String[0];
41 }
42
43
44 public static String[] getSupportedProtocols(String content_type)
45 {
46
47 return new String[0];
48 }
49
50
51 public static Player createPlayer(String locator)
52 throws IOException, MediaException
53 {
54
55 return null;
56 }
57
58
59 public static Player createPlayer(InputStream stream, String type)
60 throws IOException, MediaException
61 {
62
63 if( type.equals( "audio/x-wav" ) || type.equals( "audio/basic" ) ||
64 type.equals( "audio/mpeg" ) )
65 {
66 SampledAudioPlayer audPlayer = new SampledAudioPlayer();
67 audPlayer.open( stream, type );
68
69 if( vMedia == null )
70 vMedia = new Vector();
71 vMedia.add( audPlayer );
72 return audPlayer;
73 }
74 else if( type.equals( "audio/midi" ) )
75 {
76 MidiAudioPlayer midiPlayer = new MidiAudioPlayer();
77 midiPlayer.open( stream, type );
78
79 if( vMedia == null )
80 vMedia = new Vector();
81 vMedia.add( midiPlayer );
82 return midiPlayer;
83 }
84
85 return null;
86 }
87
88
89 private static final PCTone pcTone = new PCTone();
90
91 public synchronized static void playTone(int frequency, int time, int volume)
92 throws MediaException
93 {
94 pcTone.play(frequency, time, volume);
95 }
96
97 static void mediaDone( Object objMedia )
98 {
99
100 try
101 {
102 for( int index=0; vMedia != null && index<vMedia.size(); index++ )
103 {
104 if( objMedia == vMedia.elementAt( index ) )
105 vMedia.removeElementAt( index );
106 }
107 }
108 catch( ArrayIndexOutOfBoundsException e ) { return; };
109 }
110
111 static void cleanupMedia()
112 {
113 try
114 {
115 while( vMedia != null && vMedia.size() > 0 )
116 {
117 Player play = (Player) vMedia.elementAt( 0 );
118 play.close();
119 vMedia.removeElementAt( 0 );
120 }
121 }
122 catch( ArrayIndexOutOfBoundsException e ) { return; };
123 }
124
125 }
126
127
128