在之前的一个需求中,需要上传录音用于H5页面播放,所以研究了一下,在其中碰到的问题:上传的录音可以在安卓手机中播放,但是在苹果手机中不能播放,在经过各种查阅之后,修改音频编码器格式为recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
具体贴上代码:
public class RecorderActivity extends Activity {
private final String TAG = "RecorderActivity";
private Button btnStart;
private Button btnStop;
private Button btnUpload;
private TextView text;
private MediaRecorder recorder;
private boolean isSDCardExit; // 判断SDCard是否存在
private File SDPathDir;
private File tempFile;
private String urlStr = "http://192.168.1.61:8080/recorder/aaa.txt"; //这是上传到服务器的地址
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnStart = (Button) findViewById(R.id.btnStart);
btnStop = (Button) findViewById(R.id.btnStop);
btnUpload = (Button) findViewById(R.id.btnUpload);
text = (TextView) findViewById(R.id.text);
btnStart.setEnabled(true);
btnStop.setEnabled(false);
btnUpload.setEnabled(false);
isSDCardExit = Environment.getExternalStorageState().eq