音乐播放类

news/2024/10/23 5:49:39/

/*
 * localaudioplayer.java
 *
 * created on 2006年10月9日, 下午10:52
 *
 * to change this template, choose tools | options and locate the template under
 * the source creation and management node. right-click the template and choose
 * open. you can then make changes to the template in the source editor.
 */

 

package netbeans.david.mah_jong;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.*;
/**
 *作者:戴俊华 软件大三的游戏方向学生
 *这个类实现了本地音乐资源的播放,以及状态的转换
 *同时播放器的参数也可以设置
 *希望有用
 *转载请带上本地url以及作者
 */
public class localaudioplayer{
    public player player;
    public  string filename;
    public string format;
    public boolean succ=true;
    public localaudioplayer(string filename,string format, boolean loadfile)
   {
      this.format= format;
      this.filename = filename;
      if(loadfile)
        loadfromeresource();//加载资源
   }
   public localaudioplayer(string filename, string format)
   {
      this.format = format;
      this.filename =filename;
   }
  
    public localaudioplayer()
   {
      this.format = null;
      this.filename =null;
   }

 

   public void loadfromeresource() {
    try {
      inputstream is = getclass().getresourceasstream(filename);///把资源加载进输入流
      player = manager.createplayer(is, format);
    }
    catch(ioexception ex){
        succ=false;
    }
    catch(mediaexception ex){
        succ=false;
    }
  }
  public void setloop()//设置一直循环播放
  {
    if(player!=null)
        player.setloopcount(-1);
  }
  public void setvolume(int level)//音量控制 level范围是0--100
  {
    if(player!=null){
      volumecontrol control = (volumecontrol)player.getcontrol("volumecontrol");
      control.setlevel(level);
     }
  }
  public void stop()
  {
    if(player!=null){
      try{
        player.stop();
       }catch(mediaexception ex){

 

       }
    }
  }
  public void play()
  {
    if(player!=null){
      try{
        player.deallocate();//实现播放器的状态装换
        player.realize();
        player.prefetch();
        player.start();
      }catch(mediaexception ex){
        succ=false;
      }
    }
  }
  public void replay()//重新播放一次,先释放资源再加载进入
  {
    close();
    system.gc();//释放
    loadfromeresource();//加载
    play();
  }
  public void close()
  {
    if(player!=null){
     player.close();//关闭播放器
     player=null;
    }
  }
}


http://www.ppmy.cn/news/407474.html

相关文章

2010年第3期新刊上市:移动大时代谁在掘金?

本期封面报道:移动大时代谁在掘金? 随着3G牌照的发放,中国的移动应用正酝酿着一股淘金热潮;海内外移动应用商店纷纷破土而出,更是为移动开发者大开方便之门。如何把握这次历史机遇?本刊特别邀请了挖掘到移动应用第一…

音乐播放器之--在线音乐播放

在线播放音乐并不难,也就是传入的Url是一个网络地址。这里我要实现一个可以进行网络缓冲的在线音乐播放。 下面介绍具体实现过程: 定义一个具有缓冲效果的播放器:Player 我们看到的缓冲效果,是通过设置拖动条SeekBar的二级进度实…

Android音乐播放器

自己用4个下午的时间4个晚上上半夜的时间1次吃泡面的时间Android音乐播放器。 Apk下载地址: 点击打开链接 亲...听歌只需甩甩手机哦,亲...欢迎下载. 源代码下载地址:点击打开链接V1.0 好长时间没有写博客了 前几天有人要源代码下载地址&…

Andriod本地音乐播放器

实现本地音乐播放器(Client) 这个稍微简单点:全是Andriod知识。 学习链接:Andriod本地音乐播放的学习(这有讲课的大佬给的源码,需要自己去看视频自己去下载)(当然我的项目源码在后…

error “Incompatible build options“

问题1 CGAL环境,fatal error C1189: #error : "Incompatible build options" #if defined(__MSVC_RUNTIME_CHECKS) && !defined(_DEBUG) pragma message(“Using the /RTC option without specifying a debug runtime will lead to linker error…

播放音乐

HTML除了可以插入图形之外,还可以播放音乐和视频等。用浏览器可以播放的音乐格式有:MIDI音乐、WAV音乐、AU格式。另外在利用网络下载的各种音乐格式中,MP3是压缩率最高,音质最好的文件格式。 点播音乐 将音乐做成一个链接&#xf…

android 音乐播放器

java学习手册,最全java学习资料下载 服务和广播实现音乐播放器 先看示例: MusiceService代码 package mm.shandong.com.testsimplemedia.service;import android.app.Service; import android.content.BroadcastReceiver; import android.content.C…

综合项目_音乐播放器

<!DOCTYPE html> <html><head><meta charset"utf-8"><title>音乐播放器</title><style type"text/css"> keyframes rotate{0%{transform: rotate(0);}50%{transform:rotate(200deg);}100%{transform: rotate(0…