Ich versuche, viele Videos von 30 Sekunden im Hintergrund zu reocord, aber nach 20 oder 30 Videos mein Service, der stoping ist und starten den Prozess aufzeichnen gehen langsam.Fehler Aufnahme Videos Android
Ich habe versucht, mit einem Service im selben Prozess und das Problem war das gleiche.
Meine Video-Handler:
@Override
public void onCreate() {
super.onCreate();
isRunning = true;
idAlerta = Common.getStorage().getString(Constants.ID_ALERTA_SERVICE, "");
videoCount = 1;
mIntentRecorder = new Intent(VideoHandlerService.this, RecorderService.class);
mIntentSend = new Intent(VideoHandlerService.this, SendVideoService.class);
updateVideoTime();
mIntentRecorder.putExtra(Constants.VIDEO_TIME, videoTime);
mIntentRecorder.putExtra(Constants.ID_ALERTA_SERVICE, idAlerta);
mIntentRecorder.putExtra(Constants.COUNT_ALERTA, videoCount);
startService(mIntentRecorder);
newVideo();
}
public void newVideo() {
Common.log("new Video");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
videoCount++;
startNewVideo();
if (videoCount == 2)
sendVideo(4000);
}
}, videoTime + 2000);
}
public void startNewVideo() {
final Intent intentRecorder = new Intent(VideoHandlerService.this, RecorderService.class);
intentRecorder.putExtra(Constants.VIDEO_TIME, videoTime);
Common.log("idAlerta " + idAlerta);
intentRecorder.putExtra(Constants.ID_ALERTA_SERVICE, idAlerta);
intentRecorder.putExtra(Constants.COUNT_ALERTA, videoCount);
stopService(intentRecorder);
if (Common.getStorage().getBoolean(Constants.RECORDER_ACTIVE, false)) {
if (Common.getStorage().getString(Constants.ID_ALERTA_SERVICE, "") != null && Common.getStorage().getString(Constants.ID_ALERTA_SERVICE, "").length() > 0) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Common.log("Start service recorder");
startService(intentRecorder);
newVideo();
}
}, 5000);
}
} else
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startNewVideo();
}
}, 5000);
}
Und dies ist der Prozess zur Aufzeichnung:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Common.log("onStartCommand");
if (intent != null && ((Common.getStorage().getString(Constants.ID_ALERTA_SERVICE, "") != null && Common.getStorage().getString(Constants.ID_ALERTA_SERVICE, "").length() > 0))) {
windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
mLayoutParams = new WindowManager.LayoutParams(
1, 1,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT
);
mLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
//Cojo Información del videohandler
Common.log("Intent distinto de null");
mVideoTime = intent.getIntExtra(Constants.VIDEO_TIME, 15000);
mIdAlerta = intent.getStringExtra(Constants.ID_ALERTA_SERVICE);
mVideoCount = intent.getIntExtra(Constants.COUNT_ALERTA, 1);
Common.log("Video time" + mVideoTime);
Common.getStorage().putBoolean(Constants.RECORDER_ACTIVE, true);
initRecording();
}
return START_NOT_STICKY;
}
public void initRecording() {
Common.log("INIT RECORDING IN");
surfaceView = new SurfaceView(this);
windowManager.addView(surfaceView, mLayoutParams);
surfaceView.getHolder().addCallback(this);
Common.log("INIT RECORDING OUT");
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onDestroy() {
Common.log("onDestroy Video");
PreferenceHelper preferenceHelper = PreferenceHelper.newInstance(RecorderService.this, Constants.USER_PREFERENCES);
preferenceHelper.setBoolean(Constants.IS_RECORDING, false);
try {
camera.setPreviewCallback(null);
} catch (Exception e){
Common.log("error setPrevieCallback" + (e.getMessage() != null ? e.getMessage() : "sin mensaje"));
}
try {
muteSounds(false);
} catch (Exception e) {
Common.log(e.getMessage());
}
try {
Common.log("media recorder stop");
mediaRecorder.stop();
Common.log("media recorder reset");
mediaRecorder.reset();
Common.log("media recorder release");
mediaRecorder.release();
Common.log("media camera lock");
camera.lock();
Common.log("media camera release");
camera.release();
} catch (Exception e) {
}
Common.log("onDestroy Video");
Common.getStorage().putBoolean(Constants.RECORDER_ACTIVE, false);
RecorderService.super.onDestroy();
System.exit(0);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
mSurfaceHolder = holder;
Common.log("SurfaceCreated");
try {
try {
muteSounds(true);
} catch (Exception e) {
Common.log(e.getMessage());
}
Common.log("CAMERA OPEN 1");
try {
camera = Camera.open(1);
} catch (RuntimeException e) {
Common.log(e.getMessage());
}
Common.log("CAMERA OPEN 2");
///////////////////////////
mCamCoderProfile = CamcorderProfile.get(1, CamcorderProfile.QUALITY_LOW);
mCamCoderProfile.videoCodec = MediaRecorder.VideoEncoder.MPEG_4_SP;
mCamCoderProfile.audioCodec = MediaRecorder.AudioEncoder.AAC;
///////////////////////////
startRecorder();
} catch (Exception e) {
if (e.getMessage() != null)
Common.log(e.getMessage());
}
}
public void muteSounds(boolean mute) {
Common.log("MUTE SOUNDS IN");
AudioManager mgr = ((AudioManager) getSystemService(Context.AUDIO_SERVICE));
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (mute) {
mgr.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_MUTE, 0);
mgr.adjustVolume(AudioManager.ADJUST_MUTE, 0);
mgr.adjustVolume(AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE, 0);
} else {
mgr.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_UNMUTE, 0);
mgr.adjustVolume(AudioManager.ADJUST_UNMUTE, 0);
}
} else {
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, mute);
mgr.setStreamMute(AudioManager.STREAM_MUSIC, mute);
if (mute) {
mOlderVolumen = mgr.getStreamVolume(AudioManager.STREAM_RING);
mgr.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
} else
mgr.setStreamVolume(AudioManager.STREAM_RING, mOlderVolumen, 0);
mgr.adjustVolume(AudioManager.ADJUST_LOWER, 0);
}
Common.log("MUTE SOUNDS OUT");
}
public void startRecorder() {
mediaRecorder = new MediaRecorder();
camera.unlock();
mediaRecorder.setCamera(camera);
mediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setProfile(mCamCoderProfile);
videoFile = new File(Environment.getExternalStorageDirectory() + "/" +
"wbunker_" + mIdAlerta + "_" + mVideoCount + ".mp4");
Common.log("Video rercorder name file " + videoRecording);
mediaRecorder.setOutputFile(videoFile.getPath());
mediaRecorder.setOrientationHint(270);
try {
Common.log("mediaRecorder prepare");
mediaRecorder.prepare();
Common.log("mediaRecorder prepare");
} catch (Exception e) {
}
Common.log("mediaRecorder start");
mediaRecorder.start();
Common.log("mediaRecorder start");
Common.log("Estoy grabando macho");
}
Wenn ich den Dienst der Dienste beendet, aber die Kamera freigegeben wird, nicht einmal zu stoppen versuchen zu töten die App. Kann mir jemand helfen?? Danke im Voraus.
Sie könnten versuchen, 'Kamera = null hinzuzufügen;' 'nach camera.release (); '. Es könnte das Problem lösen. Hier mehr Info http://stackoverflow.com/questions/16705487/how-to-release-camera-after-activity-ends-in-android –
Danke, aber ich habe es schon versucht, jedenfalls ist das Hauptproblem nicht zu veröffentlichen und das Aufnehmen der Kamera, das Hauptproblem ist das Video stoppt die Aufnahme von selbst, ohne Fehler oder Ausnahme, stoppt einfach, als ob die Kamera eingefroren war – javisilox
Sie sollten es auf vielen Geräten testen, um eine bessere Perspektive Ihres Problems zu bekommen. Aus meiner Erfahrung kann sich eine Kamera anders verhalten als eine andere. – Nativ