2017-02-08 14 views
0

ビデオを録音してファイルに保存しようとしていますが、録音時にエラーが発生し続けます。Xamarin-ビデオを録画してファイルに保存する方法

Unhandled Exception: 
Java.IO.IOException: invalid preview surface. 

私はあなたが私を与えることができ、ヘルプのいずれかのビットが大好き:コードが

using System;   
using Android.App; 
using Android.OS; 
using Android.Widget; 
using Android.Media; 
using System.Timers; 
using Android.Content; 
using System.IO; 

namespace ShowHouseDemo2._1 
{ 
    [Activity(Label = "VideoPage", Icon = "@drawable/icon")] 
//Intent intent = GetInTent(); 
class VideoPage : Activity 
{ 

    //Intent string Vid = Intent.GetStringExtra("VidSent"); 
    MediaRecorder recorder; 
    Timer StartTimer; 
    int StartCount = 0; 
    protected override void OnCreate(Bundle bundle) 
    { 

     base.OnCreate(bundle); 
     SetContentView(Resource.Layout.VidTakerPage); 

     var video = FindViewById<VideoView>(Resource.Id.UserVid); 
     //string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath. "/UserVid4.mp4"; 
     // string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + ; 
     var documents = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); 
     var filename = Path.Combine(documents, "Write.txt"); 
     File.WriteAllText(filename, "Write this text into a file!"); 

     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(filename); 
     recorder.SetPreviewDisplay(video.Holder.Surface); 
     recorder.Prepare(); 
     recorder.Start(); 

     timerStarted(); 
    } 

    private void timerStarted() 
    { 
     base.OnResume(); 
     StartTimer = new Timer(); 
     StartTimer.Interval = 1000; 
     StartTimer.Elapsed += delegate 
     { 
      while (StartCount < 10) 
      { 
       if (StartCount == 9) 
       { 
        RunOnUiThread(() => 
        { 
         Intent k = new Intent(this, typeof(TakeVideo)); 

         this.StartActivity(k); 
        }); 
       } 
       StartCount++; 
      } 
     }; 
    } 
} 
} 

私が取得エラーです。ご質問ありがとうございます

答えて

2

サーフェイスコールバックインターフェイス(Android.Views.ISurfaceHolderCallback)を実装し、が有効で有効で有効な場合はの場合にのみISurfaceHolder.Holderを使用する必要があります。

あなたがインターフェイスの三つの方法(SurfaceDestroyedSurfaceCreatedSurfaceChanged)を実装して、あなたがVideoView.Holder.AddCallback経由でコールバックを割り当てることができ、すなわち

[Activity(Label = "VideoPage", Icon = "@drawable/icon")] 
public class VideoPage : Activity, Android.Views.ISurfaceHolderCallback 

、あなたのVideoPage活動でこれを行うことができます。

var video = FindViewById<VideoView>(Resource.Id.UserVid); 
video.Holder.AddCallback((this)); 
関連する問題