View Javadoc

1   /*
2    *  MicroEmulator
3    *  Copyright (C) 2006 Bartek Teodorczyk <barteo@barteo.net>
4    *
5    *  This library is free software; you can redistribute it and/or
6    *  modify it under the terms of the GNU Lesser General Public
7    *  License as published by the Free Software Foundation; either
8    *  version 2.1 of the License, or (at your option) any later version.
9    *
10   *  This library 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 GNU
13   *  Lesser General Public License for more details.
14   *
15   *  You should have received a copy of the GNU Lesser General Public
16   *  License along with this library; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   *  
19   *  Contributor(s):
20   *    Travis Berthelot
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          // TODO
40          return new String[0];
41      }
42      
43      
44      public static String[] getSupportedProtocols(String content_type)
45      {
46          // TODO
47          return new String[0];
48      }
49      
50      
51      public static Player createPlayer(String locator)
52              throws IOException, MediaException
53      {
54          // TODO
55          return null;
56      }
57      
58      
59      public static Player createPlayer(InputStream stream, String type)
60              throws IOException, MediaException
61      {
62          // TODO add all types, for now just simpleaudio
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      	//remove the media from our list of media to cleanup
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