2015-11-12 2 views
1

Я разрабатываю приложение с функцией видеомагнитофона. Приложение работает нормально, но после завершения записи видео и нажатия кнопки «Сохранить» приложение выходит из строя с сообщением «К сожалению, приложение остановилось». Но записанное видео сохраняется в папке как закодированное. Может кто-то помочь мне решить эту проблему, поскольку я не могу найти, где ошибка. Мои кодировок заключаются в следующем:Android: сбой камеры после нажатия save

MainActivity.java:

import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.os.Environment; 
import android.provider.MediaStore; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 
import android.widget.Toast; 
import android.widget.VideoView; 

import java.io.File; 
import java.text.SimpleDateFormat; 

public class MainActivity extends Activity { 

final static int REQUEST_VIDEO_CAPTURED = 1; 
VideoView videoviewPlay; 
private Uri fileUri; 
public static final int MEDIA_TYPE_VIDEO = 2; 



@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    Button buttonRecording = (Button) findViewById(R.id.recording); 



    buttonRecording.setOnClickListener(new Button.OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      // TODO Auto-generated method stub 
      Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE); 
      // create a file to save the video 
      fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO); 

      // set the image file name 
      intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); 
      startActivityForResult(intent, REQUEST_VIDEO_CAPTURED); 
     } 
    }); 
} 

    /** Create a file Uri for saving an image or video */ 

private static Uri getOutputMediaFileUri(int type) { 

    return Uri.fromFile(getOutputMediaFile(type)); 
} 

/** 
* Create a File for saving an image or video 
*/ 
private static File getOutputMediaFile(int type) { 

    // Check that the SDCard is mounted 
    File mediaStorageDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Do This Video/"); 


    // Create the storage directory(Do This Video) if it does not exist 
    if (!mediaStorageDir.exists()) { 

     if (!mediaStorageDir.mkdirs()) { 



      Log.d("Do This Video", "Failed to create directory MyCameraVideo."); 
      return null; 
     } 
    } 


    // Create a media file name 

    // For unique file name appending current timeStamp with file name 
    java.util.Date date = new java.util.Date(); 
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss") 
      .format(date.getTime()); 

    File mediaFile; 

    if (type == MEDIA_TYPE_VIDEO) { 

     // For unique video file name appending current timeStamp with file name 
     mediaFile = new File(mediaStorageDir.getPath() + File.separator + 
       "VID_" + timeStamp + ".mp4"); 

    } else { 
     return null; 
    } 

    return mediaFile; 
} 






@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    // TODO Auto-generated method stub 
    if(resultCode == RESULT_OK){ 
     if(requestCode == REQUEST_VIDEO_CAPTURED){ 
      fileUri = data.getData(); 
      Toast.makeText(MainActivity.this, 
        fileUri.getPath(), 
        Toast.LENGTH_LONG) 
        .show(); 
     } 
    }else if(resultCode == RESULT_CANCELED){ 
     fileUri = null; 
     Toast.makeText(MainActivity.this, 
       "Cancelled!", 
       Toast.LENGTH_LONG) 
       .show(); 
    } 
} 
} 

Любая помощь будет оценена. Спасибо.

LogCat:

11-13 13:57:54.538 27336-27336/com.example.dothis.video I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file. 
11-13 13:57:54.538 27336-27336/com.example.dothis.video I/SELinux﹕ Function: selinux_android_load_priority [1], There is no sepolicy version file. 
11-13 13:57:54.538 27336-27336/com.example.dothis.video I/SELinux﹕ Function: selinux_android_load_priority , priority version is VE=GOOGLE_POLICY 
11-13 13:57:54.538 27336-27336/com.example.dothis.video I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts 
11-13 13:57:54.543 27336-27336/com.example.dothis.video D/dalvikvm﹕ Late-enabling CheckJNI 
11-13 13:57:54.693 27336-27336/com.example.dothis.video D/TextLayoutCache﹕ Enable myanmar Zawgyi converter 
11-13 13:57:54.723 27336-27336/com.example.dothis.video D/libEGL﹕ loaded /system/lib/egl/libEGL_mali.so 
11-13 13:57:54.723 27336-27336/com.example.dothis.video D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_mali.so 
11-13 13:57:54.733 27336-27336/com.example.dothis.video D/libEGL﹕ loaded /system/lib/egl/libGLESv2_mali.so 
11-13 13:57:54.738 27336-27336/com.example.dothis.video E/﹕ Device driver API match 
Device driver API version: 23 
User space API version: 23 
11-13 13:57:54.738 27336-27336/com.example.dothis.video E/﹕ mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Fri Mar 21 13:52:50 KST 2014 
11-13 13:57:54.813 27336-27336/com.example.dothis.video D/OpenGLRenderer﹕ Enabling debug mode 0 
11-13 13:57:54.833 27336-27336/com.example.dothis.video D/TextLayoutCache﹕ Enable myanmar Zawgyi converter 
11-13 13:57:57.018 27336-27336/com.example.dothis.video W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection 
11-13 13:58:07.848 27336-27336/com.example.dothis.video D/AndroidRuntime﹕ Shutting down VM 
11-13 13:58:07.848 27336-27336/com.example.dothis.video W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41e23c08) 
11-13 13:58:07.853 27336-27336/com.example.dothis.video E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: com.example.dothis.video, PID: 27336 
    java.lang.RuntimeException: Unable to resume activity {com.example.dothis.video/com.example.dothis.video.AndroidVideoCapture}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=200, result=-1, data=null} to activity {com.example.dothis.video/com.example.dothis.video.AndroidVideoCapture}: java.lang.NullPointerException 
      at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3076) 
     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3105) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4054) 
     at android.app.ActivityThread.access$1000(ActivityThread.java:175) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1314) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:146) 
     at android.app.ActivityThread.main(ActivityThread.java:5603) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
     at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=200, result=-1, data=null} to activity {com.example.dothis.video/com.example.dothis.video.AndroidVideoCapture}: java.lang.NullPointerException 
     at android.app.ActivityThread.deliverResults(ActivityThread.java:3681) 
     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3063) 

+0

Пожалуйста, разместите логарифм. –

+0

@RohanKandwal Я добавил logcat. – marian

+1

См. Http://stackoverflow.com/q/14558240/1979347 –

ответ

1

Проблема заключается в вызове fileUri = data.getData(); в onActivityResult функции вашего кода. Вызов должен быть data.getExtras().get("data");, который получит фактические данные, переданные в intent.

Подробнее см. answer by David Wasser.

1

Вы не можете получить путь simplely по GetPath(), и вы должны проверить, если данные или data.getData равно нулю.

if(requestCode == REQUEST_VIDEO_CAPTURED){ 
     if(data == null || data.getData() ==null){ 
     //Log.e(); 
      return; 
     } 
     fileUri = data.getData(); 
     String filepath = uritofilpath(fileUri); 

    } 

GetPath:

public static String getPath(Uri uri,Context ctx) { 
     String res = null; 
     if(null==uri){ 
      return res; 
     } 
     if (uri != null && uri.toString().startsWith("file://")) { 
      return uri.toString().substring("file://".length()); 
     } 
     String[] proj = { MediaStore.Images.Media.DATA }; 
     Cursor cursor = ctx.getContentResolver().query(uri, proj, null, null, null); 
     if(cursor!=null){ 
      if(cursor.moveToFirst()){ 
       try { 
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
        res = cursor.getString(column_index); 
       }catch (Exception ignored){ 
       }finally { 
        closeCursor(cursor); 
       } 
      } 
     } 
     closeCursor(cursor); 
     return res; 
    } 
+0

им жаль, но это кодирование не работает..Мы сбой приложений .. – marian

+0

@marian Если вы не разместите свой логарифм, никто не сможет вам помочь. –

+0

просто добавьте попытку в вас onActivityResult –

Смежные вопросы