问题描述
我一直在尝试使用NDK将FFMPEG(用于播放音频)移植到Android中.我取得了一些成功
I have been trying to port FFMPEG (for playing audio) into Android using NDK. I have had some success
- 我可以构建FFMPEG并通过NDK进行链接.
- 我可以打电话给
avcodec_decode_audio3()
并解码给定的音频文件.
- I could build FFMPEG and link it via NDK.
- I could call
avcodec_decode_audio3()
and decode a given audio file.
所以在这里,我有一个从函数输出的音频缓冲区.我现在该怎么玩?任何ffmpeg家伙都可以告诉我解码和播放音频的确切步骤.我真的不知道该如何处理从avcodec_decode_audio3()
获得的音频缓冲区.
So here I have a audio buffer output from the function. How do I play this now? Any ffmpeg guys can tell me the exact steps to decode and play audio. I am really clueless of what to do with the audio buffers created I got from avcodec_decode_audio3()
.
非常感谢.
推荐答案
我已经在基于ffmpeg的android上开发了视频播放器.您可以使用AudioTrack类在设备上播放音频.
I have developed a videoplayer on android based on ffmpeg. You can use AudioTrack class to play audio onto device.
在Java中创建一个配乐对象
In Java create an audiotrack object
AudioTrack track;
bufferSize = AudioTrack.getMinBufferSize(44100,AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT)
track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize, mode);
//Play audio clip
track.play();
while(stream_is_over){
//Copy the decoded raw buffer from native code to "buffer" .....
............
track.write(buffer, 0, readBytes);
}
这篇关于使用FFMPEG播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!