Esempio n. 1
0
            public async void Start(InstaDirectInboxThread thread)
            {
                CurrentThread = thread;
                await _recordQueue.Enqueue(async() =>
                {
                    if (_recorder != null)
                    {
                        RecordingFailed?.Invoke(this, EventArgs.Empty);
                        return;
                    }

                    var fileName = string.Format("voice_{0:yyyy}-{0:MM}-{0:dd}_{0:HH}-{0:mm}-{0:ss}.mp3", DateTime.Now);
                    var cache    = await localFolder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);

                    try
                    {
                        _file     = cache;
                        _recorder = new Mp3Recorder(cache)
                        {
                            m_mediaCapture = new MediaCapture()
                        };

                        await _recorder.m_mediaCapture.InitializeAsync(/*_recorder.settings*/);


                        await _recorder.StartAsync();


                        _start = DateTime.Now;
                    }
                    catch (Exception ex)
                    {
                        _recorder.Dispose();
                        _recorder = null;

                        _file = null;

                        RecordingFailed?.Invoke(this, EventArgs.Empty);
                        return;
                    }

                    RecordingStarted?.Invoke(this, EventArgs.Empty);
                });
            }
            public async void Start(ChatRecordMode mode)
            {
                Logger.Debug(Target.Recording, "Start invoked, mode: " + mode);

                await _recordQueue.Enqueue(async() =>
                {
                    Logger.Debug(Target.Recording, "Enqueued start invoked");

                    if (_recorder != null)
                    {
                        Logger.Debug(Target.Recording, "_recorder != null, abort");

                        RecordingFailed?.Invoke(this, EventArgs.Empty);
                        return;
                    }

                    // Create a new temporary file for the recording
                    var fileName = string.Format(mode == ChatRecordMode.Video
                        ? "video_{0:yyyy}-{0:MM}-{0:dd}_{0:HH}-{0:mm}-{0:ss}.mp4"
                        : "voice_{0:yyyy}-{0:MM}-{0:dd}_{0:HH}-{0:mm}-{0:ss}.ogg", DateTime.Now);
                    var cache = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);

                    try
                    {
                        _mode     = mode;
                        _file     = cache;
                        _recorder = new OpusRecorder(cache, mode == ChatRecordMode.Video);

                        _recorder.m_mediaCapture = new MediaCapture();

                        if (mode == ChatRecordMode.Video)
                        {
                            var cameraDevice = await _recorder.FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Front);
                            if (cameraDevice == null)
                            {
                                // TODO: ...
                            }

                            // Figure out where the camera is located
                            if (cameraDevice.EnclosureLocation == null || cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Unknown)
                            {
                                // No information on the location of the camera, assume it's an external camera, not integrated on the device
                                _recorder._externalCamera = true;
                            }
                            else
                            {
                                // Camera is fixed on the device
                                _recorder._externalCamera = false;

                                // Only mirror the preview if the camera is on the front panel
                                _recorder._mirroringPreview = cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front;
                            }

                            _recorder.settings.VideoDeviceId = cameraDevice.Id;
                        }

                        await _recorder.m_mediaCapture.InitializeAsync(_recorder.settings);

                        Logger.Debug(Target.Recording, "Devices initialized, starting");

                        await _recorder.StartAsync();

                        Logger.Debug(Target.Recording, "Recording started at " + DateTime.Now);

                        _start = DateTime.Now;
                    }
                    catch (Exception ex)
                    {
                        Logger.Debug(Target.Recording, "Failed to initialize devices, abort: " + ex);

                        _recorder.Dispose();
                        _recorder = null;

                        _file = null;

                        RecordingFailed?.Invoke(this, EventArgs.Empty);
                        return;
                    }

                    RecordingStarted?.Invoke(this, EventArgs.Empty);
                });
            }
Esempio n. 3
0
    private static void RemoveAllEventHandlers()
    {
        if (RecordingStarted != null)
        {
            foreach (LuYou.RecordingStartedDelegate del in RecordingStarted.GetInvocationList())
            {
                RecordingStarted -= del;
            }
        }
        if (RecordingStoped != null)
        {
            foreach (LuYou.RecordingStopedDelegate del in RecordingStoped.GetInvocationList())
            {
                RecordingStoped -= del;
            }
        }
        if (RecordingFailed != null)
        {
            foreach (LuYou.RecordingFailedDelegate del in RecordingFailed.GetInvocationList())
            {
                RecordingFailed -= del;
            }
        }
        if (RecordingWarning != null)
        {
            foreach (LuYou.RecordingWarningDelegate del in RecordingWarning.GetInvocationList())
            {
                RecordingWarning -= del;
            }
        }
        if (RecordingTime != null)
        {
            foreach (LuYou.RecordingTimeDelegate del in RecordingTime.GetInvocationList())
            {
                RecordingTime -= del;
            }
        }
        if (RecordingStarted != null)
        {
            foreach (LuYou.RecordingStartedDelegate del in RecordingStarted.GetInvocationList())
            {
                RecordingStarted -= del;
            }
        }
        if (SharerPreing != null)
        {
            foreach (LuYou.SharerPreingDelegate del in SharerPreing.GetInvocationList())
            {
                SharerPreing -= del;
            }
        }

        if (SharerPrepared != null)
        {
            foreach (LuYou.SharerPreparedDelegate del in SharerPrepared.GetInvocationList())
            {
                SharerPrepared -= del;
            }
        }
        if (SharerFailed != null)
        {
            foreach (LuYou.SharerFailedDelegate del in SharerFailed.GetInvocationList())
            {
                SharerFailed -= del;
            }
        }

        if (SharerProgress != null)
        {
            foreach (LuYou.SharerProgressDelegate del in SharerProgress.GetInvocationList())
            {
                SharerProgress -= del;
            }
        }
        if (SharerComplete != null)
        {
            foreach (LuYou.SharerCompleteDelegate del in SharerComplete.GetInvocationList())
            {
                SharerComplete -= del;
            }
        }
        if (SharerStarted != null)
        {
            foreach (LuYou.SharerStartedDelegate del in SharerStarted.GetInvocationList())
            {
                SharerStarted -= del;
            }
        }
    }