|
|
|
@ -5,7 +5,7 @@ import android.media.AudioManager; |
|
|
|
|
import android.media.AudioTrack; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 音频播放器 |
|
|
|
|
* AudioPlayer: use AudioTrack and OpenSL ES to play audio |
|
|
|
|
* Created by frank on 2018/2/1. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
@ -13,11 +13,13 @@ public class AudioPlayer { |
|
|
|
|
static { |
|
|
|
|
System.loadLibrary("media-handle"); |
|
|
|
|
} |
|
|
|
|
//调用AudioTrack播放
|
|
|
|
|
|
|
|
|
|
//using AudioTrack to play
|
|
|
|
|
public native void play(String audioPath); |
|
|
|
|
//调用OpenSL ES播放
|
|
|
|
|
|
|
|
|
|
//using OpenSL ES to play
|
|
|
|
|
public native void playAudio(String audioPath); |
|
|
|
|
//调用OpenSL ES播放
|
|
|
|
|
|
|
|
|
|
public native void stop(); |
|
|
|
|
|
|
|
|
|
public native static void lameInitDefault(); |
|
|
|
@ -39,9 +41,10 @@ public class AudioPlayer { |
|
|
|
|
public native static void lameClose(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 创建一个AudioTrack对象 |
|
|
|
|
* @param sampleRate 采样率 |
|
|
|
|
* @param channels 声道布局 |
|
|
|
|
* Create an AudioTrack instance for JNI call |
|
|
|
|
* |
|
|
|
|
* @param sampleRate sampleRate |
|
|
|
|
* @param channels channel layout |
|
|
|
|
* @return AudioTrack |
|
|
|
|
*/ |
|
|
|
|
public AudioTrack createAudioTrack(int sampleRate, int channels) { |
|
|
|
|