基本的视频录制问题 [英] Issues with basic video recording
问题描述
所以我遵循的首发视频录制应用程序默认的食谱,但我遇到了,我想不通的错误。我得到的错误是在记录prepare()。跟它/0/test.mp4:打开失败:ENOENT(没有这样的文件或目录)现在我会贴code我在下面,误差是45行我也已经设置正确的权限为
<使用许可权的android:NAME =android.permission.CAMERA/>
<使用许可权的android:NAME =android.permission.CAPTURE_SECURE_VIDEO_OUTPUT/>
<使用许可权的android:NAME =android.permission.CAPTURE_VIDEO_OUTPUT/>
<使用许可权的android:NAME =android.permission.RECORD_AUDIO/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
我以为这是罚款,我从recpie添加了CAMERA和RECORD_AUDIO,然后我从发布到谷歌上搜索之前,这个问题增加了其他三个。
使用系统;使用Android.App;
使用Android.Content;
使用Android.Runtime;
使用Android.Views;
使用Android.Widget;
使用Android.OS;
使用Android.Media;命名空间CameraTest
{
[活动(标签=CameraTest,MainLauncher = true时,图标=@绘制/图标)]
公共类MainActivity:活动
{
MediaRecorder记录; 保护覆盖无效的OnCreate(束束)
{
base.OnCreate(包); 的setContentView(Resource.Layout.Main);
VAR纪录= FindViewById<按钮和GT; (Resource.Id.Record);
VAR停止= FindViewById<按钮和GT; (Resource.Id.Stop);
VAR玩= FindViewById<按钮和GT; (Resource.Id.Play);
VAR视频= FindViewById< VideoView> (Resource.Id.SampleVideoView);
Android.OS.Environment.ExternalStorageDirectory.SetWritable(真);
字符串路径= Android.OS.Environment.ExternalStorageDirectory.Name +/test.mp4
//从主布局资源设置我们的观点
//从布局资源获取我们的按钮,
//和事件附加到它
record.Click + = {委托
video.StopPlayback(); 记录=新MediaRecorder();
recorder.SetVideoSource(VideoSource.Camera);
recorder.SetAudioSource(AudioSource.Mic);
recorder.SetOutputFormat(OutputFormat.Default);
recorder.SetVideoEn codeR(VIDEOEN coder.Default);
recorder.SetAudioEn codeR(AudioEn coder.Default);
recorder.SetOutputFile(路径);
recorder.Set $ P $ pviewDisplay(video.Holder.Surface);
。录音机prepare();
recorder.Start(); }; stop.Click + = {委托
如果(录像机!= NULL){
recorder.Stop();
recorder.Release();
}
}; play.Click + = {委托
VAR URI = Android.Net.Uri.Parse(路径);
video.SetVideoURI(URI);
video.Start();
};
}
保护覆盖无效的OnDestroy()
{
base.OnDestroy(); 如果(录像机!= NULL){
recorder.Release();
recorder.Dispose();
记录= NULL;
}
}
}
}
修改
路径字符串= Android.OS.Environment.ExternalStorageDirectory.Name +/test.mp4
要:
路径字符串= Android.OS.Environment.ExternalStorageDirectory.AbsolutePath +/test.mp4
您原来的code只使用目录的名称未在完整路径作为输出位置。
So I followed the default recipe for a starter video recording app, but I am running into errors that I cannot figure out. The error I am getting is on recorder.Prepare(); it is saying /0/test.mp4: Open Failed: ENOENT (no such file or directory) Now I will paste the code I below, error is line 45. Also I have set permissions correctly as
<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" />
I assumed this was fine as I added the "CAMERA and RECORD_AUDIO" from the recpie and then I added the other three from googling this issue prior to posting.
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;
}
}
}
}
Change
string path = Android.OS.Environment.ExternalStorageDirectory.Name + "/test.mp4";
To:
string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/test.mp4";
Your original code only uses the directory name not the full path as the output location.
这篇关于基本的视频录制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!