1

我有简单的标准代码,它记录视频如下

    public class TtActivity extends Activity {
    /** Called when the activity is first created. */

        File videoFile;
        Uri fileUri;

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

        videoFile = new File(Environment.getExternalStorageDirectory(),"test.mp4");

        if(!videoFile.exists()){

            try {
                    videoFile.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
        }


        Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(videoFile));
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
        startActivityForResult(intent, 1);






    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == 1){

            if(resultCode == RESULT_OK){

                Toast.makeText(TtActivity.this, "File saved at "+videoFile.getPath(), Toast.LENGTH_SHORT).show();

            }

            else if (resultCode == RESULT_CANCELED) {

                Toast.makeText(TtActivity.this, "Recording cancelled..", Toast.LENGTH_SHORT).show();

                }

            else{

                Toast.makeText(TtActivity.this, "Capturing failed..", Toast.LENGTH_SHORT).show();

            }

        }




}

在清单中我有

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tt.cc"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-feature android:name="android.hardware.camera" android:required="false" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="TtActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

所以我的问题是在录制完成后创建文件但视频文件的大小为 0 字节...因此无法播放它..所以请帮我解决这个问题..我正在我的 htc 愿望手机上测试它.

4

1 回答 1

0

尝试这个...

intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 200);

有关更多信息,请参阅链接...

于 2012-04-30T08:32:22.890 回答