我的应用程序在我的Nexus 4上运行得非常好但是当我尝试让它在S3上进行测试时它不起作用时,媒体播放器似乎是出了问题
以下是启动媒体播放器的按钮的代码
play_sound_1 = (Button) findViewById(R.id.play_sound_1);
play_sound_1.animate().setDuration(dur);
play_sound_1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
try {
playSound1();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
play_sound_1.animate().setInterpolator(sDecelerator)
.scaleX(.85f).scaleY(.85f);
} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
play_sound_1.animate().setInterpolator(sOvershooter)
.scaleX(1f).scaleY(1f);
}
return false;
}
});
public void playSound1() throws Exception{
//Play sound
PlaybackHandler.playRecording1(SOUND_ONE);
}
PlayBack Handler类代码:
static void playRecording1(String output) throws Exception{
ditchMediaPlayer1();
mediaPlayer1 = new MediaPlayer();
mediaPlayer1.setDataSource(output);
mediaPlayer1.prepare();
mediaPlayer1.start();
}
private static void ditchMediaPlayer1() {
if(mediaPlayer1 != null){
try{
mediaPlayer1.release();
}catch(Exception e){
e.printStackTrace();
}
}
}
以下是我录制音频文件的代码,以防问题可能在这里:
rec_sound_1 = (ImageButton) findViewById(R.id.rec_sound_1);
rec_sound_1.animate().setDuration(dur);
rec_sound_1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
//begin recording
try {
RecordingHandler.beginRecording1(SOUND_ONE);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
rec_sound_1.animate().setInterpolator(sDecelerator)
.scaleX(.85f).scaleY(.85f);
} else if (arg1.getAction() == MotionEvent.ACTION_UP) {
rec_sound_1.animate().setInterpolator(sOvershooter)
.scaleX(1f).scaleY(1f);
//stop recording
RecordingHandler.stopRecording1();
}
return false;
}
});
RecordingHandler类
static void beginRecording1(String output) throws Exception {
ditchMediaRecorder1();
File outFile = new File(output);
if(outFile.exists())
outFile.delete();
recorder1 = new MediaRecorder();
recorder1.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder1.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder1.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
recorder1.setAudioEncodingBitRate(16);
recorder1.setAudioSamplingRate(44100);
recorder1.setOutputFile(output);
recorder1.prepare();
recorder1.start();
}
private static void ditchMediaRecorder1() {
//if we have the recorder, release it
if(recorder1 != null)
recorder1.release(); }
static void stopRecording1() {
if(recorder1 != null)
recorder1.stop(); }
TLDR;这是堆栈跟踪:
04-18 21:01:21.691: W/MediaPlayer(11767): info/warning (973, 0)
04-18 21:01:21.691: V/MediaPlayer(11767): callback application
04-18 21:01:21.691: V/MediaPlayer(11767): back from callback
04-18 21:01:21.701: V/MediaPlayer(11767): message received msg=5, ext1=0, ext2=0
04-18 21:01:21.701: V/MediaPlayer(11767): New video size 0 x 0
04-18 21:01:21.701: V/MediaPlayer(11767): callback application
04-18 21:01:21.701: V/MediaPlayer(11767): back from callback
04-18 21:01:21.701: V/MediaPlayer(11767): message received msg=1, ext1=0, ext2=0
04-18 21:01:21.701: V/MediaPlayer(11767): prepared
04-18 21:01:21.701: V/MediaPlayer(11767): signal application thread
04-18 21:01:21.701: V/MediaPlayer(11767): callback application
04-18 21:01:21.701: V/MediaPlayer(11767): prepare complete - status=0
04-18 21:01:21.701: V/MediaPlayer-JNI(11767): start
04-18 21:01:21.701: V/MediaPlayer(11767): start
04-18 21:01:21.701: V/MediaPlayer(11767): back from callback
04-18 21:01:21.771: I/MediaPlayer(11767): Info (973,0)
04-18 21:01:21.771: I/MediaPlayer(11767): Don't send intent. msg.arg1 = 0, msg.arg2 = 0