Справочник Пользователя для Motorola C550

Скачать
Страница из 86

Gaming API and Sound  
 
39 
BackgroundMusic Class 
The 
BackgroundMusic
 class encapsulates the data for a game's background music. 
A game may create several 
BackgroundMusic
 objects, but only one can be playing at 
any one time. The sound data can be stored on the device as a named resource in the 
application JAR file, or it can be stored on a server and retrieved via the network. 
BackgroundMusic
 is played by a 
GameScreen
.  
BackgroundMusic Methods 
The 
BackgroundMusic
 class defines the following methods:
 
• 
public static BackgroundMusic
 
createBackgroundMusic(java.lang.String name)
 throws 
FileFormatNotSupportedException
 – Creates a BackgroundMusic for 
the sound data stored in the specified named resource or URL. This method currently 
supports the use of MIDI format 0 and format 1 only. 
Using BackgroundMusic 
The following code sample shows implementation of 
BackgroundMusic
Using BackgroundMusic 
BackgroundMusic bgm1 = BackgroundMusic.createBackgroundMusic("/FunkyTunes.mid"); 
BackgroundMusic bgm2 = 
BackgroundMusic.createBackgroundMusic("http://www.motorola.com/sounds/JazzyTunes.mid");
 
The following code sample shows implementation of the Gaming API that contains a 
sound API: 
Gaming API containing a sound API 
import com.motorola.game.*; 
public class GS extends GameScreen { 
  
 public BackgroundMusic bgm; 
  
 public GS() 
 { 
   bgm = BackgroundMusic.createBackgroundMusic("vinovata.mid"); 
   playBackgroundMusic(bgm, true); 
 }