ビデオを録画してカスタムフォルダーに保存するアプリケーションを開発し、コードは問題なく、構文エラーはありません...しかし、電話でアプリを実行すると、録画が終了した後、プロセスを強制的に閉じるようになりました。 ? これが私のコードです...
public class MainActivity extends Activity {
private static final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 200;
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);
//create new Intent
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO); // create a file to save the video
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high*/
// start the Video Capture Intent
startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// Video captured and saved to fileUri specified in the Intent
Toast.makeText(this, "Video saved to :\n" +
fileUri, Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the video capture
} else {
// Video capture failed, advise user
}
}
}
/** Create a file Uri for saving an image or video */
private static Uri getOutputMediaFileUri(int type){
return Uri.fromFile(getOutputMediaFile(type));
}
public void inputFileName(){
}
/** Create a File for saving an image or video */
private static File getOutputMediaFile(int type){
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "MyCameraApp");
// This location works best if you want the created images to be shared
// between applications and persist after your app has been uninstalled.
// Create the storage directory if it does not exist
if (! mediaStorageDir.exists()){
if (! mediaStorageDir.mkdirs()){
Log.d("MyCameraApp", "failed to create directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
if(type == MEDIA_TYPE_VIDEO) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"VID_"+ timeStamp + ".mp4");
} else {
return null;
}
return mediaFile;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
私のマニフェスト
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cameratesting"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10"/>
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_OWNER_DATA" />
<uses-permission android:name="android.permission.WRITE_OWNER_DATA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
私のlogcat(com.example.cameratesting)
11-25 21:14:19.799: I/ActivityManager(160): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.cameratesting/.MainActivity bnds=[62,153][118,218] } from pid 234
11-25 21:14:35.719: I/ActivityManager(160): Start proc com.example.cameratesting for activity com.example.cameratesting/.MainActivity: pid=14732 uid=10052 gids={1006, 1015}
11-25 21:14:38.409: I/ActivityManager(160): Displayed com.example.cameratesting/.MainActivity: +1m10s22ms (total +2s710ms)
11-25 21:14:52.359: I/InputDispatcher(160): Delivering key to current input target: action: 0, channel '408c2d78 com.example.cameratesting/com.example.cameratesting.MainActivity (server)'
11-25 21:14:52.540: I/InputDispatcher(160): Delivering key to current input target: action: 1, channel '408c2d78 com.example.cameratesting/com.example.cameratesting.MainActivity (server)'
11-25 21:21:14.450: I/ActivityManager(160): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.cameratesting/.MainActivity bnds=[62,153][118,218] } from pid 234
11-25 21:21:14.500: W/ActivityManager(160): Trying to launch com.example.cameratesting/.MainActivity
11-25 21:21:35.159: I/ActivityManager(160): Displayed com.example.cameratesting/.MainActivity: +20s664ms
11-25 21:21:59.180: I/ActivityManager(160): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.cameratesting/.MainActivity bnds=[62,153][118,218] } from pid 234
11-25 21:22:07.600: I/InputDispatcher(160): Delivering key to current input target: action: 0, channel '40916378 com.example.cameratesting/com.example.cameratesting.MainActivity (server)'
11-25 21:22:07.779: I/InputDispatcher(160): Delivering key to current input target: action: 1, channel '40916378 com.example.cameratesting/com.example.cameratesting.MainActivity (server)'
11-25 21:22:08.879: E/ATK(13151): com.example.cameratesting
11-25 21:22:12.579: I/PackageManager(160): Removing non-system package:com.example.cameratesting
11-25 21:22:12.579: I/ActivityManager(160): Force stopping package com.example.cameratesting uid=10052
11-25 21:22:12.759: D/PackageManager(160): Scanning package com.example.cameratesting
11-25 21:22:12.769: I/PackageManager(160): Package com.example.cameratesting codePath changed from /data/app/com.example.cameratesting-1.apk to /data/app/com.example.cameratesting-2.apk; Retaining data and using new
11-25 21:22:12.769: I/PackageManager(160): Unpacking native libraries for /data/app/com.example.cameratesting-2.apk
11-25 21:22:13.709: D/PackageManager(160): Activities: com.example.cameratesting.MainActivity
11-25 21:22:13.709: I/ActivityManager(160): Force stopping package com.example.cameratesting uid=10052
11-25 21:22:13.709: W/PackageManager(160): Code path for pkg : com.example.cameratesting changing from /data/app/com.example.cameratesting-1.apk to /data/app/com.example.cameratesting-2.apk
11-25 21:22:13.709: W/PackageManager(160): Resource path for pkg : com.example.cameratesting changing from /data/app/com.example.cameratesting-1.apk to /data/app/com.example.cameratesting-2.apk
11-25 21:22:13.959: D/PackageManager(160): New package installed in /data/app/com.example.cameratesting-2.apk
11-25 21:22:13.959: W/PackageManager(160): Unknown permission android.permission.READ_OWNER_DATA in package com.example.cameratesting
11-25 21:22:13.959: W/PackageManager(160): Unknown permission android.permission.WRITE_OWNER_DATA in package com.example.cameratesting
11-25 21:22:13.959: W/PackageManager(160): Unknown permission android.permission.READ_EXTERNAL_STORAGE in package com.example.cameratesting
11-25 21:22:14.209: I/ActivityManager(160): Force stopping package com.example.cameratesting uid=10052
11-25 21:22:15.619: I/UinboxLogger(15063): [UinboxReceiver] onReceive() >> intent.getData() : com.example.cameratesting
11-25 21:22:15.639: V/PackageIntentReceiver(13466): onReceive() intent:Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:com.example.cameratesting flg=0x10000000 cmp=com.sec.android.app.controlpanel/.PackageIntentReceiver (has extras) } pkg:com.example.cameratesting action:android.intent.action.PACKAGE_REMOVED
11-25 21:22:17.499: I/ActivityManager(160): Force stopping package com.example.cameratesting uid=10052
11-25 21:22:17.499: I/ActivityManager(160): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.cameratesting/.MainActivity } from pid 15065
11-25 21:22:17.549: I/ActivityManager(160): Start proc com.example.cameratesting for activity com.example.cameratesting/.MainActivity: pid=15085 uid=10052 gids={1006, 1015}
11-25 21:22:17.789: W/ActivityThread(15085): Application com.example.cameratesting is waiting for the debugger on port 8100...
11-25 21:22:22.879: V/PackageIntentReceiver(13466): onReceive() intent:Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.example.cameratesting flg=0x10000000 cmp=com.sec.android.app.controlpanel/.PackageIntentReceiver (has extras) } pkg:com.example.cameratesting action:android.intent.action.PACKAGE_ADDED
11-25 21:22:30.319: I/ActivityManager(160): No longer want com.example.cameratesting (pid 15085): hidden #16
11-25 21:22:50.849: I/ActivityManager(160): Start proc com.example.cameratesting for activity com.example.cameratesting/.MainActivity: pid=15285 uid=10052 gids={1006, 1015}
11-25 21:22:53.029: I/ActivityManager(160): Displayed com.example.cameratesting/.MainActivity: +35s490ms (total +2s192ms)
11-25 21:22:53.979: I/InputDispatcher(160): Delivering key to current input target: action: 0, channel '408b9c80 com.example.cameratesting/com.example.cameratesting.MainActivity (server)'
11-25 21:22:54.119: I/InputDispatcher(160): Delivering key to current input target: action: 1, channel '408b9c80 com.example.cameratesting/com.example.cameratesting.MainActivity (server)'
11-25 21:22:55.299: E/ATK(13151): com.example.cameratesting
11-25 21:25:42.270: I/ActivityManager(160): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.cameratesting/.MainActivity bnds=[62,153][118,218] } from pid 234
11-25 21:25:42.349: I/ActivityManager(160): Start proc com.example.cameratesting for activity com.example.cameratesting/.MainActivity: pid=15542 uid=10052 gids={1006, 1015}
11-25 21:26:00.489: I/ActivityManager(160): Displayed com.example.cameratesting/.MainActivity: +18s151ms
11-25 21:26:03.149: I/InputDispatcher(160): Delivering key to current input target: action: 0, channel '407d0678 com.example.cameratesting/com.example.cameratesting.MainActivity (server)'
11-25 21:26:03.209: I/InputDispatcher(160): Delivering key to current input target: action: 1, channel '407d0678 com.example.cameratesting/com.example.cameratesting.MainActivity (server)'
logcat(ビデオカメラ)
11-25 21:14:19.829: I/ActivityManager(160): Start proc com.sec.android.app.camera for activity com.sec.android.app.camera/.Camcorder: pid=14663 uid=10040 gids={1006, 1015}
11-25 21:14:20.669: E/Camcorder(14663): Initialize Camcorder Sound
11-25 21:14:20.959: I/ActivityManager(160): Displayed com.sec.android.app.camera/.Camcorder: +1s149ms
11-25 21:14:21.899: I/QualcommCameraHardware(95): <=PCAM=>NOW CAMCORDER MODE~~~~~~
11-25 21:14:25.019: I/InputDispatcher(160): Delivering touch to current input target: action: 0, channel '40974370 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:14:25.129: I/InputDispatcher(160): Delivering touch to current input target: action: 1, channel '40974370 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:14:25.479: E/VENC_ENC(95): VENC_MSG_HIGH venci_process_command_init::3105 initializing camcorder application...
11-25 21:14:25.499: E/VENC_ENC(95): VENC_MSG_HIGH venci_init_encoder::2391 set camcorder rate control config...
11-25 21:14:25.529: E/VENC_DRV(95): VENC_MSG_HIGH venc_drv_start::614 camcorder pass for DSP
11-25 21:14:28.609: I/InputDispatcher(160): Delivering touch to current input target: action: 0, channel '40974370 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:14:28.639: I/InputDispatcher(160): Delivering touch to current input target: action: 1, channel '40974370 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:14:29.099: E/AndroidRuntime(14663): at com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1151)
11-25 21:14:29.099: E/AndroidRuntime(14663): at com.sec.android.app.camera.CamcorderEngine.doStopVideoRecordingSync(CamcorderEngine.java:780)
11-25 21:14:29.119: W/ActivityManager(160): Force finishing activity com.sec.android.app.camera/.Camcorder
11-25 21:14:29.619: W/ActivityManager(160): Activity pause timeout for HistoryRecord{40545450 com.sec.android.app.camera/.Camcorder}
11-25 21:14:36.399: I/ActivityManager(160): Starting: Intent { act=android.media.action.VIDEO_CAPTURE cmp=com.sec.android.app.camera/.Camcorder (has extras) } from pid 14732
11-25 21:14:36.469: W/ActivityManager(160): Trying to launch com.sec.android.app.camera/.Camcorder
11-25 21:14:37.989: I/WindowManager(160): WIN DEATH: Window{40974370 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder paused=false}
11-25 21:14:45.769: W/ActivityManager(160): Activity destroy timeout for HistoryRecord{40545450 com.sec.android.app.camera/.Camcorder}
11-25 21:21:14.600: I/ActivityManager(160): Starting: Intent { act=android.media.action.VIDEO_CAPTURE cmp=com.sec.android.app.camera/.Camcorder (has extras) } from pid 14732
11-25 21:21:14.620: I/ActivityManager(160): Start proc com.sec.android.app.camera for activity com.sec.android.app.camera/.Camcorder: pid=14960 uid=10040 gids={1006, 1015}
11-25 21:21:15.750: E/Camcorder(14960): Initialize Camcorder Sound
11-25 21:21:15.960: I/ActivityManager(160): Displayed com.sec.android.app.camera/.Camcorder: +1s340ms (total +1s458ms)
11-25 21:21:16.920: I/QualcommCameraHardware(95): <=PCAM=>NOW CAMCORDER MODE~~~~~~
11-25 21:21:22.989: I/InputDispatcher(160): Delivering touch to current input target: action: 0, channel '40c36608 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:21:23.079: I/InputDispatcher(160): Delivering touch to current input target: action: 1, channel '40c36608 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:21:23.349: E/VENC_ENC(95): VENC_MSG_HIGH venci_process_command_init::3105 initializing camcorder application...
11-25 21:21:23.349: E/VENC_ENC(95): VENC_MSG_HIGH venci_init_encoder::2391 set camcorder rate control config...
11-25 21:21:23.369: E/VENC_DRV(95): VENC_MSG_HIGH venc_drv_start::614 camcorder pass for DSP
11-25 21:21:27.329: I/InputDispatcher(160): Delivering touch to current input target: action: 0, channel '40c36608 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:21:27.439: I/InputDispatcher(160): Delivering touch to current input target: action: 1, channel '40c36608 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:21:27.709: E/AndroidRuntime(14960): at com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1151)
11-25 21:21:27.709: E/AndroidRuntime(14960): at com.sec.android.app.camera.CamcorderEngine.doStopVideoRecordingSync(CamcorderEngine.java:780)
11-25 21:21:27.739: W/ActivityManager(160): Force finishing activity com.sec.android.app.camera/.Camcorder
11-25 21:21:28.249: W/ActivityManager(160): Activity pause timeout for HistoryRecord{40d17e40 com.sec.android.app.camera/.Camcorder}
11-25 21:21:36.739: I/WindowManager(160): WIN DEATH: Window{40c36608 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder paused=false}
11-25 21:21:45.170: W/ActivityManager(160): Activity destroy timeout for HistoryRecord{40d17e40 com.sec.android.app.camera/.Camcorder}
11-25 21:22:20.139: I/ActivityManager(160): Starting: Intent { act=android.media.action.VIDEO_CAPTURE cmp=com.sec.android.app.camera/.Camcorder (has extras) } from pid 15085
11-25 21:22:20.189: I/ActivityManager(160): Start proc com.sec.android.app.camera for activity com.sec.android.app.camera/.Camcorder: pid=15105 uid=10040 gids={1006, 1015}
11-25 21:22:22.099: E/Camcorder(15105): Initialize Camcorder Sound
11-25 21:22:22.369: I/ActivityManager(160): Displayed com.sec.android.app.camera/.Camcorder: +2s184ms (total +4s829ms)
11-25 21:22:23.489: I/QualcommCameraHardware(95): <=PCAM=>NOW CAMCORDER MODE~~~~~~
11-25 21:22:34.229: I/InputDispatcher(160): Delivering touch to current input target: action: 0, channel '409d4988 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:22:34.329: I/InputDispatcher(160): Delivering touch to current input target: action: 1, channel '409d4988 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:22:34.639: E/VENC_ENC(95): VENC_MSG_HIGH venci_process_command_init::3105 initializing camcorder application...
11-25 21:22:34.679: E/VENC_ENC(95): VENC_MSG_HIGH venci_init_encoder::2391 set camcorder rate control config...
11-25 21:22:34.699: E/VENC_DRV(95): VENC_MSG_HIGH venc_drv_start::614 camcorder pass for DSP
11-25 21:22:44.099: I/InputDispatcher(160): Delivering touch to current input target: action: 0, channel '409d4988 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:22:44.159: I/InputDispatcher(160): Delivering touch to current input target: action: 1, channel '409d4988 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:22:44.439: E/AndroidRuntime(15105): at com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1151)
11-25 21:22:44.439: E/AndroidRuntime(15105): at com.sec.android.app.camera.CamcorderEngine.doStopVideoRecordingSync(CamcorderEngine.java:780)
11-25 21:22:44.439: W/ActivityManager(160): Force finishing activity com.sec.android.app.camera/.Camcorder
11-25 21:22:44.949: W/ActivityManager(160): Activity pause timeout for HistoryRecord{4096e880 com.sec.android.app.camera/.Camcorder}
11-25 21:22:51.329: I/ActivityManager(160): Starting: Intent { act=android.media.action.VIDEO_CAPTURE cmp=com.sec.android.app.camera/.Camcorder (has extras) } from pid 15285
11-25 21:22:51.389: W/ActivityManager(160): Trying to launch com.sec.android.app.camera/.Camcorder
11-25 21:22:52.669: I/WindowManager(160): WIN DEATH: Window{409d4988 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder paused=false}
11-25 21:23:00.939: W/ActivityManager(160): Activity destroy timeout for HistoryRecord{4096e880 com.sec.android.app.camera/.Camcorder}
11-25 21:25:42.509: I/ActivityManager(160): Starting: Intent { act=android.media.action.VIDEO_CAPTURE cmp=com.sec.android.app.camera/.Camcorder (has extras) } from pid 15542
11-25 21:25:42.529: I/ActivityManager(160): Start proc com.sec.android.app.camera for activity com.sec.android.app.camera/.Camcorder: pid=15550 uid=10040 gids={1006, 1015}
11-25 21:25:43.379: E/Camcorder(15550): Initialize Camcorder Sound
11-25 21:25:43.599: I/ActivityManager(160): Displayed com.sec.android.app.camera/.Camcorder: +1s81ms (total +1s257ms)
11-25 21:25:44.609: I/QualcommCameraHardware(95): <=PCAM=>NOW CAMCORDER MODE~~~~~~
11-25 21:25:47.169: I/InputDispatcher(160): Delivering touch to current input target: action: 0, channel '40a5e5a8 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:25:47.299: I/InputDispatcher(160): Delivering touch to current input target: action: 1, channel '40a5e5a8 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:25:47.559: E/VENC_ENC(95): VENC_MSG_HIGH venci_process_command_init::3105 initializing camcorder application...
11-25 21:25:47.599: E/VENC_ENC(95): VENC_MSG_HIGH venci_init_encoder::2391 set camcorder rate control config...
11-25 21:25:47.609: E/VENC_DRV(95): VENC_MSG_HIGH venc_drv_start::614 camcorder pass for DSP
11-25 21:25:52.289: I/InputDispatcher(160): Delivering touch to current input target: action: 0, channel '40a5e5a8 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:25:52.409: I/InputDispatcher(160): Delivering touch to current input target: action: 1, channel '40a5e5a8 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder (server)'
11-25 21:25:52.689: E/AndroidRuntime(15550): at com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1151)
11-25 21:25:52.689: E/AndroidRuntime(15550): at com.sec.android.app.camera.CamcorderEngine.doStopVideoRecordingSync(CamcorderEngine.java:780)
11-25 21:25:52.699: W/ActivityManager(160): Force finishing activity com.sec.android.app.camera/.Camcorder
11-25 21:25:53.209: W/ActivityManager(160): Activity pause timeout for HistoryRecord{40a6f418 com.sec.android.app.camera/.Camcorder}
11-25 21:26:01.899: I/WindowManager(160): WIN DEATH: Window{40a5e5a8 com.sec.android.app.camera/com.sec.android.app.camera.Camcorder paused=false}
11-25 21:26:10.360: W/ActivityManager(160): Activity destroy timeout for HistoryRecord{40a6f418 com.sec.android.app.camera/.Camcorder}