关于错误 start failed: -2147483648

package com.example.project0828_mediarecorder;



import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;


import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class MainActivity extends Activity {


private Button btn_start;
private Button btn_stop;
MediaRecorder mediaRecorder;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn_start = (Button) findViewById(R.id.btn_start);
btn_stop = (Button) findViewById(R.id.btn_stop);
mediaRecorder = new MediaRecorder();
btn_start.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String name = new SimpleDateFormat("yyyyMMddkkmmss")
.format(new Date()) + ".mrc";
String path = Environment.getExternalStorageDirectory()
+ File.separator + "Music" + File.separator + name;
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);


mediaRecorder
.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder
.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mediaRecorder.setOutputFile(path);
try {
mediaRecorder.prepare();
mediaRecorder.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
btn_stop.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
mediaRecorder.stop();
mediaRecorder.reset();
// mediaRecorder.release();
// mediaRecorder.reset();
}
});
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}


@Override
protected void onDestroy() {
// TODO Auto-generated method stub
mediaRecorder.release();
mediaRecorder = null;
super.onDestroy();
}
}



今天遇到这个问题,很揪心,从网上找了好长时间,都是问题,没有被解决的,可能是自己没找到吧,闲话少说

我们一般运行时是在模拟器上,因为模拟器没有麦克风,所以第一次开启后,你在点击停止,它就跟吃了炫迈一样,根本停不下来,就算你写了释放,也不管用,后来我就在手机上运行了,真的成功了。温馨提示,记得写权限android.permission.WRITE_EXTERNAL_STORAGE跟android.permission.RECORD_AUDIO,还有就是手机运行提示请求选择允许,好了就这么多了


当然,你还可以这样改一下,把mediaRecorder = new MediaRecorder();放在开始录制里边,然后在停止里边写上

mediaRecorder.stop();

mediaRecorder.release();

mediaRecorder=null;

这样也是可以的,但不是很实用


发布了1 篇原创文章 · 获赞 0 · 访问量 3863
展开阅读全文

小米手机播放视频报错stop called in state 1,error (-38, 0)

01-27

今天写demo,用小米手机播放手机里本地的视频,界面正常,但是视频不出现,在log里报错如下: 01-27 10:53:46.530: E/MediaPlayer-JNI(21091): QCMediaPlayer mediaplayer NOT present 01-27 10:53:46.700: E/MediaPlayer-JNI(21091): QCMediaPlayer mediaplayer NOT present 01-27 10:53:46.820: E/MediaPlayer(21091): stop called in state 1 01-27 10:53:46.820: E/MediaPlayer(21091): error (-38, 0) 01-27 10:53:46.830: E/MediaPlayer(21091): start called in state 0 01-27 10:53:46.840: E/MediaPlayer(21091): Attempt to perform seekTo in wrong state: mPlayer=0x0, mCurrentState=0 01-27 10:53:46.880: E/MediaPlayer(21091): Error (-38,0) 01-27 10:53:46.920: E/MediaPlayer(21091): Should have subtitle controller already set 代码如下: try { player = new MediaPlayer(); // 重置为初始状态 player.reset(); // 设置音乐流的类型 player.setAudioStreamType(AudioManager.STREAM_MUSIC); // 设置video影片以surfaceviewholder播放 player.setDisplay(holder); // 设置路径 player.setDataSource(Environment.getExternalStorageDirectory() .getAbsolutePath() + "/VideoCache/1453791771643.mp4"); player.prepareAsync(); if (player != null) { player.stop(); } player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { player.start(); } }); } catch (Exception e) { Log.e("HHHHHHHHHHHHHHHHHH", e.toString()); e.printStackTrace(); } 手机里还有个视频文件能播放,这个就不行,郁闷。 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览