使用 Java 进入复杂的音频世界我正在使用这个库,它基本上是我在 Github 上改进和发布的。
库的主类是StreamPlayer,代码有注释,简单易懂。
问题是它支持除速度增加/降低音频速度之外的许多功能。假设当您更改视频速度时,就像 YouTube 所做的那样。
我不知道如何实现这样的功能。我的意思是,将音频写入采样率时我该怎么办targetFormat?我每次都必须一次又一次地重新启动音频....
AudioFormat targetFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, sourceFormat.getSampleRate()*2, nSampleSizeInBits, sourceFormat.getChannels(),
nSampleSizeInBits / 8 * sourceFormat.getChannels(), sourceFormat.getSampleRate(), false);
Run Code Online (Sandbox Code Playgroud)
播放音频的代码是:
/**
* Main loop.
*
* Player Status == STOPPED || SEEKING = End of Thread + Freeing Audio Resources.<br>
* Player Status == PLAYING = Audio stream data sent to Audio line.<br>
* Player Status == PAUSED = Waiting for another status.
*/ …Run Code Online (Sandbox Code Playgroud)