我是靠谱客的博主 爱听歌钢铁侠,最近开发中收集的这篇文章主要介绍java如何重复播放,如何重复在Java中的音频文件,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

How would i get the audio file to repeat continuously? Right now the music just plays once and that;s it. I am trying to get the sound to repeat over and over. Would I have to get the audio file another way or is there a simpler way?

Code:

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStream;

import sun.audio.AudioPlayer;

import sun.audio.AudioStream;

public class Sound {

public static void music(String fileName) {

try {

InputStream in = new FileInputStream(new File(fileName));

AudioStream audioStream = new AudioStream(in);

AudioPlayer.player.start(audioStream);

} catch (IOException e) {

e.printStackTrace();

}

}

}

How i call it:

// Plays the music.

public void music() {

Sound.music("res/music/I Like Your Hat.wav");

}

解决方案

Don't use sun.* packages, these are private packages and may not always be available. Take a look at this example for some ideas on how to get a audio clip to play.

Take a look at Clip and Clip#loop

As a very simple example...

AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(...);

Clip clip = AudioSystem.getClip();

clip.open(audioInputStream);

clip.loop(Clip.LOOP_CONTINUOUSLY);

clip.start();

最后

以上就是爱听歌钢铁侠为你收集整理的java如何重复播放,如何重复在Java中的音频文件的全部内容,希望文章能够帮你解决java如何重复播放,如何重复在Java中的音频文件所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部