Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
SoundEffects.java
Package: J2ME&Game.rar [view]
Upload User: gyyuli
Upload Date: 2013-07-09
Package Size: 3050k
Code Size: 2k
Category:
J2ME
Development Platform:
Java
- import javax.microedition.media.*;
- import java.io.*;
- class SoundEffects
- {
- private static SoundEffects instance;
- private Player blastSoundPlayer;
- private SoundEffects()
- {
- blastSoundPlayer = createPlayer("/blast.wav", "audio/x-wav");
- }
- static SoundEffects getInstance()
- {
- if (instance == null)
- {
- instance = new SoundEffects();
- }
- return instance;
- }
- void startBlastSound()
- {
- startPlayer(blastSoundPlayer);
- }
- void startGameOverSound()
- {
- startPlayer(createPlayer("/gameover.mid", "audio/midi"));
- }
- void startHighScoreSound()
- {
- startPlayer(createPlayer("/highscore.mid", "audio/midi"));
- }
- private void startPlayer(Player p)
- {
- if (p != null)
- {
- try
- {
- p.stop();
- p.setMediaTime(0L);
- p.start();
- }
- catch (MediaException me)
- {
- // ignore
- }
- }
- }
- private Player createPlayer(String filename, String format)
- {
- Player p = null;
- try
- {
- InputStream is = getClass().getResourceAsStream(filename);
- p = Manager.createPlayer(is, format);
- p.prefetch();
- }
- catch (IOException ioe)
- {
- // ignore
- }
- catch (MediaException me)
- {
- // ignore
- }
- return p;
- }
- }