科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道[冷枫]MIDP2.0声音用法

[冷枫]MIDP2.0声音用法

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

MIDP2.0声音用法

作者:冷枫 来源:CSDN 2007年9月24日

关键字: 冷枫 MIDP 声音

  • 评论
  • 分享微博
  • 分享邮件

//游戏关卡控制  private int gameLevel = 0;//  //游戏音乐控制  private Player treadSoundPlayer;  Player backgroundMusicPlayer;  private int volumeLevel = 100; //音量大小的控制  private VolumeControl vc;  private boolean playState = false; //(播放/关闭)状态 ////////////////////////////////声音处理///////////////////////////////////////  public void playerUpdate(Player p, String event, Object eventData) { //player监听    try {      if (event == PlayerListener.END_OF_MEDIA) {        playState = false;      }      if (event == PlayerListener.STARTED) {        playState = true;//       this.musicVolume();      }    }    catch (Exception e) {      System.out.println("Error at 11: " + event + e.toString());    }  }  protected void musicStart() { //随机产生一个音乐    try {      backgroundMusicPlayer = null;      backgroundMusicPlayer = createPlayer("/2c.mid", "audio/midi");//      backgroundMusicPlayer.addPlayerListener(this);//      backgroundMusicPlayer.setLoopCount( -1);        vc = (VolumeControl) backgroundMusicPlayer.getControl("VolumeControl");        if (vc != null)        {          if (gameLevel == 0)            backgroundMusicPlayer.setLoopCount( -1);          else            backgroundMusicPlayer.setLoopCount(5);          backgroundMusicPlayer.start();        }    }    catch (Exception e) {      System.out.println("Error at 20: " + backgroundMusicPlayer + e.toString());    }  }  protected void musicClose() { //关掉音乐    try {      if(backgroundMusicPlayer != null){   backgroundMusicPlayer.close();   backgroundMusicPlayer = null; }    }    catch (Exception e) {      System.out.println("Error at 30: " + e.toString());    }  }  protected void musicPause() { //暂停音乐    try {      if (backgroundMusicPlayer != null && playState)        pausetime = backgroundMusicPlayer.getMediaTime();      backgroundMusicPlayer.stop();    }    catch (Exception e) {      System.out.println("Error at 40:" + e.toString());    }  }  protected void musicContinue() { //音乐继续    try {      if (backgroundMusicPlayer != null && !playState)        backgroundMusicPlayer.setMediaTime(pausetime);      backgroundMusicPlayer.start();    }    catch (Exception e) {      System.out.println("Error at 50:" + e.toString());    }  }  protected void musicVolume()                         //设置音乐的音量   {     if (vc != null)       vc.setLevel(volumeLevel);   }  protected Player createPlayer(String filename, String format) { //创建音乐    Player p = null;    try {      InputStream is = getClass().getResourceAsStream(filename);      p = Manager.createPlayer(is, format);      p.prefetch();    }    catch (Exception x) {      System.out.println("Error at 60: " + filename + x.toString());    }    return p;  }

 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=330523

    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章