简体   繁体   English

在java中暂停mp3

[英]pausing mp3 in java

I'm currently working on a project in which i need to play a background mp3 sound. 我正在制作一个项目,我需要播放背景mp3声音。 I managed to do that using the Jlayer library and a piece of code found here 我设法使用Jlayer库和这里找到的一段代码

However, I needed to add some more features to this code, such as loop playing and pause. 但是,我需要为此代码添加更多功能,例如循环播放和暂停。
The loop function was fairly easy to implement, but i've spent hours looking for a way to pause and resume mp3 files. 循环函数很容易实现,但我花了几个小时寻找暂停和恢复mp3文件的方法。

My guess would have been to use the play(int frames) method in the Player class, using the getPosition() method and the mp3 total frame number, but i can't manage to get the total frame number. 我的猜测是在Player类中使用play(int frames)方法,使用getPosition()方法和mp3总帧数,但我无法设法得到总帧数。

Any clue ? 任何线索? I just need this pause/resume method, so if you know one way different from this, feel free to post 我只需要这种暂停/恢复方法,所以如果你知道一种与此不同的方法,请随意发布

i've also been trying some stuff with the BasicPlayer library (link here ), but i always end up getting javax.sound.sampled.UnsupportedAudioFileException when trying to read any mp3 file 我也一直在尝试使用BasicPlayer库(链接在这里 ),但我总是在尝试读取任何mp3文件时得到javax.sound.sampled.UnsupportedAudioFileException

You can't do that with the Default Player implementation. 您无法使用默认播放器实现执行此操作。

You need to implement the stream classes and read data which those DataSourceLine classes. 您需要实现流类并读取那些DataSourceLine类的数据。 It's a bit hard work, but it's possible. 这是一项艰苦的工作,但这是可能的。 I did it 2 years ago, if I found my code I post it to you. 我是2年前做的,如果我发现了我的代码,我会把它发给你。

Standard Java Sound provides all the functionality stated in the question. 标准Java Sound提供了问题中陈述的所有功能。 To add MP3 (decoding) support to Java Sound, add the mp3plugin.jar (of the JMF) to the run-time class-path of the application. 要向Java Sound添加MP3(解码)支持,请将mp3plugin.jar (JMF)添加到应用程序的运行时类路径中。

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

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