java实现播放音频

发布时间:2024-04-17 10:20:17

在使用swing做桌面端开发时,有时候需要播放一些音频

package com.course.util;
import java.io.InputStream;

import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

/*
 * @通用背景音乐播放模块
 * @version 1.0
 */
public class MusicDemo {
	public MusicDemo(){
		init();
	}
	public void init() {
		//方法三
		InputStream in = null;
		try {
        	in=this.getClass().getResourceAsStream("/com/course/sounds/logic.mid"); 
			AudioStream as = new AudioStream(in);
			AudioPlayer.player.start(as);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}


Card image cap
应用宝
Card image cap
APP STORE
Card image cap
应用宝
Card image cap
小米