Пример #1
0
        /// <summary>
        /// Register callbacks in order to handle VLC dialogs.
        /// LibVLC 3.0.0 and later.
        /// </summary>
        /// <param name="error">Called when an error message needs to be displayed.</param>
        /// <param name="login">Called when a login dialog needs to be displayed.
        /// You can interact with this dialog by calling Dialog.PostLogin() to post an answer or Dialog.Dismiss() to cancel this dialog.</param>
        /// <param name="question">Called when a question dialog needs to be displayed.
        /// You can interact with this dialog by calling Dialog.PostLogin() to post an answer or Dialog.Dismiss() to cancel this dialog.</param>
        /// <param name="displayProgress">Called when a progress dialog needs to be displayed.</param>
        /// <param name="updateProgress">Called when a progress dialog needs to be updated.</param>
        public void SetDialogHandlers(DisplayError error, DisplayLogin login, DisplayQuestion question,
                                      DisplayProgress displayProgress, UpdateProgress updateProgress)
        {
            _error           = error ?? throw new ArgumentNullException(nameof(error));
            _login           = login ?? throw new ArgumentNullException(nameof(login));
            _question        = question ?? throw new ArgumentNullException(nameof(question));
            _displayProgress = displayProgress ?? throw new ArgumentNullException(nameof(displayProgress));
            _updateProgress  = updateProgress ?? throw new ArgumentNullException(nameof(updateProgress));

            Native.LibVLCDialogSetCallbacks(NativeReference, DialogCb, GCHandle.ToIntPtr(_gcHandle));
        }
Пример #2
0
        public void SetDialogHandlers(DisplayError error, DisplayLogin login, DisplayQuestion question,
                                      DisplayProgress displayProgress, UpdateProgress updateProgress)
        {
            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }
            if (login == null)
            {
                throw new ArgumentNullException(nameof(login));
            }
            if (question == null)
            {
                throw new ArgumentNullException(nameof(question));
            }
            if (displayProgress == null)
            {
                throw new ArgumentNullException(nameof(displayProgress));
            }
            if (updateProgress == null)
            {
                throw new ArgumentNullException(nameof(updateProgress));
            }

            var dialogCbs = new DialogCallbacks
            {
                DisplayError = (data, title, text) =>
                {
                    // no dialogId ?!
                    error(title, text);
                },
                DisplayLogin = (data, id, title, text, username, store) =>
                {
                    var cts = new CancellationTokenSource();
                    var dlg = new Dialog(new DialogId {
                        NativeReference = id
                    });
                    _cts.Add(id, cts);
                    login(dlg, title, text, username, store, cts.Token);
                },
                DisplayQuestion = (data, id, title, text, type, cancelText, firstActionText, secondActionText) =>
                {
                    var cts = new CancellationTokenSource();
                    var dlg = new Dialog(new DialogId {
                        NativeReference = id
                    });
                    _cts.Add(id, cts);
                    question(dlg, title, text, type, cancelText, firstActionText, secondActionText, cts.Token);
                },
                DisplayProgress = (data, id, title, text, indeterminate, position, cancelText) =>
                {
                    var cts = new CancellationTokenSource();
                    var dlg = new Dialog(new DialogId {
                        NativeReference = id
                    });
                    _cts.Add(id, cts);
                    displayProgress(dlg, title, text, indeterminate, position, cancelText, cts.Token);
                },
                Cancel = (data, id) =>
                {
                    if (_cts.TryGetValue(id, out var token))
                    {
                        token.Cancel();
                        _cts.Remove(id);
                    }
                },
                UpdateProgress = (data, id, position, text) =>
                {
                    var dlg = new Dialog(new DialogId {
                        NativeReference = id
                    });
                    updateProgress(dlg, position, text);
                }
            };

            _dialogCbsPtr = Marshal.AllocHGlobal(Marshal.SizeOf <DialogCallbacks>());
            Marshal.StructureToPtr(dialogCbs, _dialogCbsPtr, true);
            Native.LibVLCDialogSetCallbacks(NativeReference, _dialogCbsPtr, IntPtr.Zero);
        }