ExPlayer.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:3k
源码类别:
J2ME
开发平台:
Java
- package exframework;
- /**
- * <p>Title: ExFramework</p>
- *
- * <p>Description: lizhenpeng</p>
- *
- * <p>Copyright: Copyright (c) 2005</p>
- *
- * <p>Company: LP&P</p>
- *
- * @author lipeng
- * @version 1.0
- */
- import javax.microedition.media.*;
- import javax.microedition.media.control.*;
- import java.io.*;
- public class ExPlayer implements AllAction,PlayerListener
- {
- public void playerUpdate(Player player,String event,Object eventData)
- {
- if(event==PlayerListener.END_OF_MEDIA)
- {
- try
- {
- player.start();
- }
- catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
- public ExPlayer()
- {
- }
- public void allAction(MainForm form)
- {
- /*
- String []contentType=Manager.getSupportedContentTypes(null);
- for(int i = 0;i<contentType.length;i++)
- {
- System.out.println(contentType[i]);
- String[] protocol = Manager.getSupportedProtocols(contentType[i]);
- for(int j= 0;j<protocol.length;j++)
- {
- System.out.print(protocol[j]+",");
- }
- System.out.println();
- }
- try
- {
- // Manager.playTone(100,1000,100);
- byte tempo=50; // set tempo to 120 bpm
- byte d=8; // eighth-note
- byte C4=ToneControl.C4;
- byte D4=(byte)(C4+2); // a whole step
- byte E4=(byte)(C4+4); // a major third
- byte G4=(byte)(C4+7); // a fifth
- byte rest=ToneControl.SILENCE; // rest
- byte[] mySequence=
- {
- ToneControl.VERSION,1, //设置版本号,当前必须设为1
- ToneControl.TEMPO,tempo, //设置声音播放速度,值越大,播放越快
- ToneControl.SET_VOLUME,100, //设置音量,值越大,音量越大
- ToneControl.BLOCK_START,0, //预定义播放块,当前块号为0
- E4,d,D4,d,C4,d,E4,d,
- E4,d,E4,d,E4,d,rest,d, //块的内容
- ToneControl.BLOCK_END,0, //块定义结束符
- ToneControl.PLAY_BLOCK,0, //播放当前块号为0的块,块号必须提前定义
- D4,d,D4,d,D4,d,rest,d, //不使用块号方式播放的内容,必须位于块定义后面
- };
- Player p=Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
- p.realize();
- //
- ToneControl c=(ToneControl)p.getControl("ToneControl");
- c.setSequence(mySequence);
- p.prefetch();
- p.start();
- }
- catch(Exception e)
- {
- }
- try
- {
- InputStream is=getClass().getResourceAsStream("/"+"Testsound.mid");
- Player player=Manager.createPlayer(is,"audio/midi");
- player.realize();
- player.prefetch();
- //System.out.println(player.getMediaTime());
- //System.out.println(player.getDuration());
- player.start();
- VolumeControl control=(VolumeControl)player.getControl("VolumeControl"); //获得控制接口,此接口的获得必须在获取播放信息或者获取播放设备后面,如果在它们前面,将会出现无法播放声音的情况
- if(control!=null) //必须检查是否为null,因为有些声音格式可能不支持音量控制
- {
- control.setLevel(5); //设置音量级别为50
- //control.setMute(true); //设置静音
- }
- //System.out.println(player.getMediaTime());
- //player.addPlayerListener(this);
- }
- catch(Exception e)
- {
- System.out.println(e);
- } */
- LPAudioPlayer player = new LPAudioPlayer("Testsound.mid","audio/midi");
- //LPAudioPlayer player2 = new LPAudioPlayer("bg.mid","audio/midi",true);
- player.threadPlay();
- }
- }