diff --git a/app/src/main/java/com/frank/ffmpeg/AudioPlayer.java b/app/src/main/java/com/frank/ffmpeg/AudioPlayer.java index d6553f5..b411682 100644 --- a/app/src/main/java/com/frank/ffmpeg/AudioPlayer.java +++ b/app/src/main/java/com/frank/ffmpeg/AudioPlayer.java @@ -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,20 +13,22 @@ 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(); public native static void lameInit(int inSamplerate, int outChannel, - int outSamplerate, int outBitrate, float scaleInput, int mode, int vbrMode, - int quality, int vbrQuality, int abrMeanBitrate, int lowpassFreq, int highpassFreq, String id3tagTitle, - String id3tagArtist, String id3tagAlbum, String id3tagYear, - String id3tagComment); + int outSamplerate, int outBitrate, float scaleInput, int mode, int vbrMode, + int quality, int vbrQuality, int abrMeanBitrate, int lowpassFreq, int highpassFreq, String id3tagTitle, + String id3tagArtist, String id3tagAlbum, String id3tagYear, + String id3tagComment); public native static int lameEncode(short[] buffer_l, short[] buffer_r, int samples, byte[] mp3buf); @@ -39,19 +41,20 @@ 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){ + public AudioTrack createAudioTrack(int sampleRate, int channels) { int audioFormat = AudioFormat.ENCODING_PCM_16BIT; int channelConfig; - if(channels == 1){ + if (channels == 1) { channelConfig = AudioFormat.CHANNEL_OUT_MONO; - }else if(channels == 2){ + } else if (channels == 2) { channelConfig = AudioFormat.CHANNEL_OUT_STEREO; - }else{ + } else { channelConfig = AudioFormat.CHANNEL_OUT_STEREO; }