简体   繁体   English

Java-如何播放带循环点的mp3

[英]Java - How to play an mp3 with looping points

I'm a bit stumped here. 我在这里有些困惑。 I need background music for the game I'm making, and for most songs, there will be a beginning section that will head into a loop once it's done playing (aka an intro). 我正在制作的游戏需要背景音乐,而且对于大多数歌曲而言,一旦开始播放(即介绍),就会有一个开始部分进入循环。 Although this seems kinda simple, I haven't been able to find anything that would do this. 尽管这似乎很简单,但我还找不到任何可以做到这一点的东西。 Could anyone help? 有人可以帮忙吗? Thanks! 谢谢!

EDIT: Screwed up a tag 编辑:搞砸了一个标签

First of all, I recommend you to use OGG instead of MP3, has better performance. 首先,我建议您使用OGG代替MP3,具有更好的性能。

You have to separate the music into two tracks, one with the intro, and one with the looping part. 您必须将音乐分为两首,一首是前奏,一首是循环曲。 In the code you have to initialize both tracks as two different Music objects. 在代码中,您必须将两个轨道初始化为两个不同的Music对象。 Set the looping in the object with the intro track to false and start playing it. 将带有介绍音轨的对象中的循环设置为false并开始播放。 Now on each cycle of the game you have to check if the intro track is playing, if not, start playing the loop (You have to make additional checkings if you can stop the music by other means, eg: pausing the game). 现在,在游戏的每个循环中,您都必须检查是否正在播放介绍性曲目,否则,请开始播放循环(如果可以通过其他方式停止音乐,例如,暂停游戏,则必须进行其他检查)。

Depending of the performance of the computer, the change will be amost unnoticeable or be a small gap. 根据计算机的性能,变化几乎是不明显的或很小的差距。

edit: 编辑:

my bad, I saw Java and automatically assumed it was Android. 不好的是,我看到Java并自动认为它是Android。

Try looking in this answer 尝试寻找这个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM