社区
J2ME
帖子详情
j2me中如何播放指定的声音文件??
xwei520
2004-09-06 03:46:33
如题;
有完整的程序更好!~
...全文
246
5
打赏
收藏
j2me中如何播放指定的声音文件??
如题; 有完整的程序更好!~
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
prok
2004-09-07
打赏
举报
回复
midp2.0可以
chengfeng
2004-09-07
打赏
举报
回复
以下是声音播放代码,不过只支持MIDP2.0,如果是MIDP1.0则要使用厂商提供的开发包了。
import java.io.*;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
public class MediaPlayer implements PlayerListener{
private Player player;
private InputStream is;
private String ctype = null;
private Hashtable players;
// private boolean startFlag = false;
// private boolean stopFlag = false;
private boolean loopPlay = false;
private String mediaUrl = null;
private String volumeLevel = null;
// private String thisTimeUrl;
private String lastTimeUrl = "";
private VolumeControl ctrl;
public MediaPlayer(){
// dThread = new Thread(this);
// dThread.start();
players = new Hashtable();
player = null;
}
public void setMediaLocation(String ml){
if (lastTimeUrl == ml)
{
Player tmpPlayer = (Player) players.get(ml);
if (tmpPlayer != null) {
player = tmpPlayer;
return;
}
}
lastTimeUrl = ml;
//System.out.println("create new");
mediaUrl = ml;
is = getClass().getResourceAsStream(ml);
if (ml.endsWith("wav")) {
ctype = "audio/x-wav";
}
else if(ml.endsWith("mid")){
ctype = "audio/midi";
}
else if(ml.endsWith("mp3")){
ctype = "audio/mpeg";
}
else ctype= "audio/x-tone-seq";
createPlayer();
}
private void createPlayer() {
try {
if (player != null)
{
player.stop();
player.close();
player = null;
System.gc();
}
Player player1 = Manager.createPlayer(is, ctype);
player1.addPlayerListener(this);
player1.realize();
players.put(mediaUrl,player1);
player = player1;
} catch (Exception e) {
System.out.println("createPlayer() "+mediaUrl+" "+e.toString());
e.printStackTrace();
}
}
public void setVolumeLevel(String vl){
volumeLevel = vl;
int level=Integer.valueOf(volumeLevel).intValue()*25;
if(player!=null){
ctrl = (VolumeControl)player.getControl("VolumeControl");
if (ctrl != null)
ctrl.setLevel(level);
}
// else System.out.println("setVolumeLevel:volume control error");
}
private void volumeLevelIs(String vl){
// VolumeControl ctrl;
int level=Integer.valueOf(volumeLevel).intValue()*25;
if(player!=null){
ctrl = (VolumeControl)player.getControl("VolumeControl");
if (ctrl != null)
ctrl.setLevel(level);
}
// else System.out.println("volumeLevelIs:volume control error");
}
public void start(){
try {
player.stop();
// volumeLevelIs(volumeLevel);
player.start();
}
catch (Exception ex){
ex.printStackTrace();
}
}
public void stop(){
try {
if (player != null) {
player.stop();
}
} catch (Exception ex) {System.out.println("stop() "+mediaUrl+" "+ex.toString());ex.printStackTrace();}
}
public void setPlayBackLoop(boolean flag)
{
if (flag==true)
loopPlay = true;
else loopPlay = false;
}
public void setMediaSource(byte abyte0[])
{
}
public void playerUpdate(Player sound, String event, Object eventData) {
if(loopPlay == true)
{
if(event==PlayerListener.END_OF_MEDIA)
start();
}
}
public void closePlayer() {
for (Enumeration e = players.elements() ; e.hasMoreElements() ;)
{
((Player)e.nextElement()).close();
}
players.clear();
}
}
minghuitian
2004-09-06
打赏
举报
回复
up
sbamdanb00
2004-09-06
打赏
举报
回复
midp1.0没声音,除非你用本地api,可以到各个厂家找文档
xwei520
2004-09-06
打赏
举报
回复
UP!~
J2ME
播放
声音
在
J2ME
中
,处理声音需要使用到Mobile Media API(MMAPI),该包是MIDP1.0的可选包,在MIDP2.0
中
已经包含了这个包。所以如果你使用MIDP1.0的话,请确认你的运行环境是否支持。 一般手机支持的
声音文件
格式为wav、mid和mpg等。具体请查阅你的手机说明文档。 在声音处理
中
,有很多处理的方式,这里说一下最常用的情况,
播放
JAR文件
中
的wav文件。
J2ME
手机开发--
播放
声音文件
的完整源代码
//可以在你的
j2me
项目
中
,用这个类文件来
播放
声音//使用方法:// source = new Source("1.mid");// source.start();//我的手机不支持mp3,^_^,没关系,我自己写个程序来放歌听,只是效果差点.import javax.microedition.media.*;import javax.
在
J2ME
程序
中
实现声音
播放
在
J2ME
中
,处理声音需要使用到Mobile Media API(MMAPI),该包是MIDP1.0的可选包,在MIDP2.0
中
已经包含了这个包。所以如果你使用MIDP1.0的话,请确认你的运行环境是否支持。 一般手机支持的...
J2me
Game开发技巧:手机游戏
中
声音
播放
及处理
在
J2ME
中
,通过Mobile Media API(MMAPI)支持手机音频,这是在特定类型的设备上支持不同程度的多媒体的类和接口的一个集合。更具体地说,Mobile Media API划分为两种不同的API集合。 手机乐音或特别的声音效果,对于手机游戏玩家来说将会是一种美妙的享受。
J2ME
音效通常分为两种:一种是
播放
已有的
声音文件
,另一种是
播放
音调。 在
J2ME
中
J2ME
学习(三)——如何
播放
声音
J2ME
学习(三)——如何
播放
声音 在
J2ME
中
,处理声音需要使用到Mobile Media API(MMAPI),该包是MIDP1.0的可选包,在MIDP2.0
中
已经包含了这个包。所以如果你使用MIDP1.0的话,请确认你的运行环境是否支持。 一般手机支持的
声音文件
格式为wav、mid和mpg等。具体请查阅你的手机说明文档。 在声音处理
中
,有很多
J2ME
13,096
社区成员
26,491
社区内容
发帖
与我相关
我的任务
J2ME
Java J2ME
复制链接
扫一扫
分享
社区描述
Java J2ME
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章