Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 基本录像的问题_Android_Xamarin_Xamarin.android_Video Capture_Xamarin Studio - Fatal编程技术网

Android 基本录像的问题

Android 基本录像的问题,android,xamarin,xamarin.android,video-capture,xamarin-studio,Android,Xamarin,Xamarin.android,Video Capture,Xamarin Studio,因此,我遵循了入门视频录制应用程序的默认配方,但我遇到了无法理解的错误。我遇到的错误在记录器上。Prepare();它是说/0/test.mp4:openfailed:enoint(没有这样的文件或目录)现在我将把代码I粘贴到下面,错误是第45行。此外,我已将权限正确设置为 <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.per

因此,我遵循了入门视频录制应用程序的默认配方,但我遇到了无法理解的错误。我遇到的错误在记录器上。Prepare();它是说/0/test.mp4:openfailed:enoint(没有这样的文件或目录)现在我将把代码I粘贴到下面,错误是第45行。此外,我已将权限正确设置为

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CAPTURE_SECURE_VIDEO_OUTPUT" />
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

我认为这很好,因为我添加了recpie中的“摄像头和录音”,然后在发布之前通过谷歌搜索添加了其他三个

using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Media;

namespace CameraTest
{
    [Activity (Label = "CameraTest", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        MediaRecorder recorder;

        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            SetContentView (Resource.Layout.Main);
            var record = FindViewById<Button> (Resource.Id.Record);
            var stop = FindViewById<Button> (Resource.Id.Stop);
            var play = FindViewById<Button> (Resource.Id.Play);       
            var video = FindViewById<VideoView> (Resource.Id.SampleVideoView);
            Android.OS.Environment.ExternalStorageDirectory.SetWritable(true);
            string path = Android.OS.Environment.ExternalStorageDirectory.Name + "/test.mp4";


            // Set our view from the "main" layout resource
            // Get our button from the layout resource,
            // and attach an event to it
            record.Click += delegate {
                video.StopPlayback ();

                recorder = new MediaRecorder ();
                recorder.SetVideoSource (VideoSource.Camera); 
                recorder.SetAudioSource (AudioSource.Mic);              
                recorder.SetOutputFormat (OutputFormat.Default);
                recorder.SetVideoEncoder (VideoEncoder.Default); 
                recorder.SetAudioEncoder (AudioEncoder.Default);      
                recorder.SetOutputFile (path);       
                recorder.SetPreviewDisplay (video.Holder.Surface);         
                recorder.Prepare ();
                recorder.Start ();   } ;

            stop.Click += delegate {
                if (recorder != null) {
                    recorder.Stop ();
                    recorder.Release ();
                }
            };

            play.Click += delegate {
                var uri = Android.Net.Uri.Parse (path);        
                video.SetVideoURI (uri);
                video.Start ();   
            };


        }
        protected override void OnDestroy ()
        {
            base.OnDestroy ();

            if (recorder != null) {
                recorder.Release ();
                recorder.Dispose ();
                recorder = null;
            }
        }
    }
}
使用系统;
使用Android.App;
使用Android.Content;
使用Android.Runtime;
使用Android.Views;
使用Android.Widget;
使用Android.OS;
使用Android.Media;
名称空间摄像师
{
[活动(Label=“CameraTest”,MainLauncher=true,Icon=“@drawable/Icon”)]
公共课活动:活动
{
媒体记录器;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
var record=findviewbyd(Resource.Id.record);
var stop=findviewbyd(Resource.Id.stop);
var play=findviewbyd(Resource.Id.play);
var video=findviewbyd(Resource.Id.SampleVideoView);
Android.OS.Environment.ExternalStorageDirectory.SetWritable(true);
字符串路径=Android.OS.Environment.ExternalStorageDirectory.Name+“/test.mp4”;
//从“主”布局资源设置视图
//从布局资源中获取我们的按钮,
//并在其上附加一个事件
记录。单击+=委派{
video.StopPlayback();
记录器=新的MediaRecorder();
recorder.SetVideoSource(VideoSource.Camera);
recorder.SetAudioSource(AudioSource.Mic);
recorder.SetOutputFormat(OutputFormat.Default);
recorder.SetVideoEncoder(VideoEncoder.Default);
recorder.SetAudioEncoder(AudioEncoder.Default);
recorder.SetOutputFile(路径);
recorder.SetPreviewDisplay(video.Holder.Surface);
记录器。准备();
Start();};
停止。单击+=委派{
if(记录器!=null){
停止();
Release();
}
};
播放。单击+=委派{
var uri=Android.Net.uri.Parse(路径);
video.SetVideoURI(uri);
video.Start();
};
}
受保护的覆盖无效OnDestroy()
{
base.ondestory();
if(记录器!=null){
Release();
Dispose();
记录器=空;
}
}
}
}
更改

 string path = Android.OS.Environment.ExternalStorageDirectory.Name + "/test.mp4";
致:


原始代码仅使用目录名称而不是完整路径作为输出位置。

此外,配方似乎不正确。现在填写错误报告。
string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/test.mp4";