dsaudio如何播放wav

dsaudio如何播放wav,第1张

VDS Audio可以播放wav格式的音乐文件。只需要把wav文件拖放到VDS Audio的主界面,即可播放。另外,你还可以使用VDS Audio的“添加文件”功能,找到你想要播放的wav文件,然后点击打开即可播放。

建议使用jmf(java media framwork),这样就能播放mp3等众多格式的音乐了;去sun官网下一个jmf,安装好后,把

jmf.jar包引入便可使用,给出例zi代码:使用方法:构造函数中传入文件路径名即可,播放、暂停、继续、停止等功能均已实现。

/*************************************************

* Subclass: MusicPlay

*************************************************/

public class MusicPlay implements Runnable {

private Time zeroTime = new Time(0)

private Player player

private boolean isloop = false

/*************************************************

* Function: MusicPlay Description: constructor, load the music file and

* get ready for play Called By: MultiMedia()

*************************************************/

// 实例化各个参数 filename 为文件名,可为绝对路径

public MusicPlay(String filename) {

File file = new File(filename)

try {

player = Manager.createRealizedPlayer(file.toURI().toURL())

player.addControllerListener(new ControllListener())

} catch (NoPlayerException e) {

e.printStackTrace()

} catch (CannotRealizeException e) {

e.printStackTrace()

} catch (MalformedURLException e) {

e.printStackTrace()

} catch (IOException e) {

e.printStackTrace()

}

}

/*************************************************

* Function: isRunning Description: test if this music is playing Called

* By:

*************************************************/

public boolean isRunning() {

return player.getState() == Player.Started

}

/*************************************************

* Function: play Description: play the music for once Called By:

* resumeAll()

*************************************************/

// 只播放一次

public void play() {

if (!turnOff)

player.start()

}

/*************************************************

* Function: replay Description: replay the music Called By: musics that

* will be played many times will invoke this methed

*************************************************/

// 再播放一次

public void replay() {

if (turnOff)

return

if (player.getState() == Controller.Prefetched)

player.setMediaTime(zeroTime)

player.start()

}

/*************************************************

* Function: stop Description: stop this music Called By: stopAll() of

* upper class,suspendAll() of upper

* class,BackroundForMenuPanel,GameOverPanel

*************************************************/

public void stop() {

player.stop()

}

/*************************************************

* Function: close Description: dispose the music Called By: closeAll()

* of super class

*************************************************/

public void close() {

player.stop()

player.close()

}

/*************************************************

* Function: loop Description: make the music played repetitiously

* Called By: music that will repetitious play

*************************************************/

// 循环播放

public void loop() {

if (turnOff)

return

isloop = true

player.prefetch()

replay()

}

/*************************************************

* Function: run Description: trig this music Called By: Override method

*************************************************/

@Override

public void run() {

loop()

}

/*************************************************

* Subclass: ControllListener Description: listener for playing and

* implement playing repetitiously

*************************************************/

// 通过对播放进度的监听,实现循环播放

private class ControllListener implements ControllerListener {

public void controllerUpdate(ControllerEvent e) {

if (e instanceof EndOfMediaEvent) {

if (isloop) {

player.setMediaTime(new Time(0))

player.start()

}

}

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/tougao/8006426.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-12
下一篇2023-04-12

发表评论

登录后才能评论

评论列表(0条)

    保存