android AudioTrack不能播放awr
我用AudioTrack播放MP3 awr都是不成功的 只会传出一堆的噪声,但是播放wav是没有问题的,因为wav就相当于原生态的pcm
这时候 我有两个选择
1、从3gp网站上下载awr解码算法 用jni调用 把awr解码成pcm
2、可以用AudioRecord来录制pcm 并用AudioTrack来播放
我用的时后者
Java代码
package com.lp;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.AudioTrack;
import android.media.MediaRecorder;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener{
private TextView stateView;
private Button btnStart,btnStop,btnPlay,btnFinish;
private RecordTask recorder;
private PlayTask player;
private File audioFile;
private boolean isRecording=true, isPlaying=false;
private int frequence = 44100;
private int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_MONO;
private int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main_pcm);
stateView = (TextView)this.findViewById(R.id.view_state);
stateView.setText("准备开始");
相关新闻>>
- 发表评论
-
- 最新评论 更多>>