Home Xamarin recording audio over a video and exporting it to youtube
Reply: 0

Xamarin recording audio over a video and exporting it to youtube

Judith Otten
1#
Judith Otten Published in 2017-12-06 14:40:18Z

I'm in the final stages of creating my Foley app! (my first ever created app during my internship, I learned how to make it myself, so sorry if any questions are stupid!)

My game is finished and working (also thanks to many of you!) and now I am trying to make the second part.

The idea is that it will show a video without sound. People then will have the opportunity to use our Foley room to record sounds over the video.

So far so good, but I still have a few issues.

First, I can't seem to find a way to stop the video/audio and replay it. When you take all the correct steps, there is no issue, but as most of you will know you want to make your code as waterproof as possible, so it would be nice to find a solution to this.

Second, I'd like to know if it's possible to export the combination of the video and recording audio to youtube. (I found a code to upload, but haven't tried if my idea is possible, does anyone have any experience with this?)

    //<-----------------------------------Aangeven variabelen--------------->
    MediaRecorder _recorder;
    MediaPlayer _player;
    Button _start;
    Button _stop;

    public static bool recorderplaying = false;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.VideoActie);

        //Videovariabelen
        var videoView = FindViewById<VideoView>(Resource.Id.PlaceHolder);
        Button play = FindViewById<Button>(Resource.Id.Play);
        Button stop = FindViewById<Button>(Resource.Id.stop);

        //opnamevariabelen
        _start = FindViewById<Button>(Resource.Id.record);
        _stop = FindViewById<Button>(Resource.Id.stop);

        //<-----------------------------------Opnemen  audio---------------->
        //Opslaan opname
        string path = $"{Android.OS.Environment.ExternalStorageDirectory.AbsolutePath}/test.3gpp";

        //Toegang vragen tot opslag android telefoon
        if (Build.VERSION.SdkInt > BuildVersionCodes.M)
        {
            if (CheckSelfPermission(Manifest.Permission.WriteExternalStorage) != Android.Content.PM.Permission.Granted
            || CheckSelfPermission(Manifest.Permission.RecordAudio) != Android.Content.PM.Permission.Granted)
            {
                RequestPermissions(new[] { Manifest.Permission.WriteExternalStorage, Manifest.Permission.RecordAudio }, 0);
            }
        }

        //<-----------------------------------Video afspelen-------------->
        //video source
        videoView.SetMediaController(new MediaController(this));
        videoView.SetVideoPath($"android.resource://{PackageName}/{Resource.Raw.puppy}");
        videoView.RequestFocus();
        //<-----------------------------------Buttons--------------------->
        //opname start
        _start.Click += delegate
        {
            _stop.Enabled = !_stop.Enabled;
            _start.Enabled = !_start.Enabled;

            _recorder.SetAudioSource(AudioSource.Mic);
            _recorder.SetOutputFormat(OutputFormat.ThreeGpp);
            _recorder.SetAudioEncoder(AudioEncoder.AmrNb);
            _recorder.SetOutputFile(path);
            _recorder.Prepare();
            _recorder.Start();
            videoView.Start();
            recorderplaying = true;
        };
        //opname stop
        stop.Click += delegate
        {
            _stop.Enabled = !_stop.Enabled;
            videoView.Pause();
            _player.Stop();
            if (recorderplaying == true)
            {
                _recorder.Stop();
                _recorder.Reset();
                recorderplaying = false;
            }
            else
            {
                int pass = 0;
            }
        };
        play.Click += delegate
        {
            _stop.Enabled = !_stop.Enabled;
            _player.SetDataSource(path);
            _player.Prepare();
            _player.Start();
            videoView.Start();
        };
    }

    //<-----------------------------------OnResume, OnPause---------------->

    protected override void OnResume()
    {
        base.OnResume();
        _recorder = new MediaRecorder();
        _player = new MediaPlayer();
        _player.Completion += (sender, e) => {
            _player.Reset();
            _start.Enabled = !_start.Enabled;
            _stop.Enabled = !_stop.Enabled;
        };
    }
    protected override void OnPause()
    {
        base.OnPause();
        _player.Release();
        _recorder.Release();
        _player.Dispose();
        _recorder.Dispose();
        _player = null;
        _recorder = null;
    }
}

}

This is what I have so far.

I also tried to make a global variable for stopping the video, since that worked fine for the audio in the game, but sadly that didn't work.

note: don't mind the puppy video, it's a placeholder haha!

If anyone has any idea if and how this is possible, that would be amazing!!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30461 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO