0
点赞
收藏
分享

微信扫一扫

J2ME中利用WTK播放已加载的WAV格式的音频

MIDlet详细代码:




package test;

import javax.microedition.midlet.*;

import javax.microedition.media.*;

import java.io.*;

public class SoundMIDlet extends MIDlet

{

private Player player = null;

/** Constructor */

public SoundMIDlet() {

try {

InputStream is = this.getClass().getResourceAsStream(
"/audio/bark.wav");

player = Manager.createPlayer(is, "audio/x-wav");

}

catch (IOException e) {

System.out.println("1:" + e);

}

catch (MediaException e) {

System.out.println("2:" + e);

}

catch (Exception e) {

System.out.println("3:" + e);

}

}

/** Main method */

public void startApp() {

if (player != null) {

try {

player.start();

}

catch (MediaException e) {

System.out.println("4:" + e);

}

}

}

/** Handle pausing the MIDlet */

public void pauseApp() {

}

/** Handle destroying the MIDlet */

public void destroyApp(boolean unconditional) {

}

}

举报

相关推荐

0 条评论