Example #1
0
        public ConvertOperationViewModel(IConvertOperation operation, IPreview preview, IMediaManager mediaManager)
            : base(operation)
        {
            _convertOperation     = operation;
            _mediaManager         = mediaManager;
            _destMediaName        = operation.DestMediaProperties.MediaName;
            _destFileName         = operation.DestMediaProperties.FileName;
            _destCategory         = operation.DestMediaProperties.MediaCategory;
            _destMediaEmphasis    = operation.DestMediaProperties is IPersistentMediaProperties ? ((IPersistentMediaProperties)operation.DestMediaProperties).MediaEmphasis : TMediaEmphasis.None;
            _destParental         = operation.DestMediaProperties.Parental;
            _destMediaVideoFormat = operation.DestMediaProperties.VideoFormat;

            _audioChannelMappingConversion = operation.AudioChannelMappingConversion;
            _aspectConversion = operation.AspectConversion;
            _audioVolume      = operation.AudioVolume;
            _sourceFieldOrderEnforceConversion = operation.SourceFieldOrderEnforceConversion;
            _duration      = operation.Duration;
            _startTC       = operation.StartTC;
            _trim          = operation.Trim;
            _loudnessCheck = operation.LoudnessCheck;
            operation.SourceMedia.PropertyChanged += OnSourceMediaPropertyChanged;
            Array.Copy(_aspectConversions, _aspectConversionsEnforce, 3);
            if (preview != null)
            {
                _previewVm = new PreviewViewmodel(preview)
                {
                    Media = operation.SourceMedia
                };
                _previewVm.PropertyChanged += _previewVm_PropertyChanged;
            }
        }
Example #2
0
        public IngestOperationViewModel(IIngestOperation operation, IPreview preview, IEngine engine)
            : base(operation)
        {
            _ingestOperation = operation;
            _engine          = engine;
            string destFileName = $"{Path.GetFileNameWithoutExtension(operation.Source.FileName)}.{operation.MovieContainerFormat}";

            _destMediaProperties = new PersistentMediaProxy
            {
                FileName      = operation.DestDirectory.GetUniqueFileName(destFileName),
                MediaName     = FileUtils.GetFileNameWithoutExtension(destFileName, operation.Source.MediaType),
                MediaType     = operation.Source.MediaType == TMediaType.Unknown ? TMediaType.Movie : operation.Source.MediaType,
                Duration      = operation.Source.Duration,
                TcStart       = operation.StartTC,
                MediaGuid     = operation.Source.MediaGuid,
                MediaCategory = operation.Source.MediaCategory
            };

            _audioChannelMappingConversion = operation.AudioChannelMappingConversion;
            _aspectConversion = operation.AspectConversion;
            _audioVolume      = operation.AudioVolume;
            _sourceFieldOrderEnforceConversion = operation.SourceFieldOrderEnforceConversion;
            _loudnessCheck = operation.LoudnessCheck;
            operation.Source.PropertyChanged += OnSourceMediaPropertyChanged;
            AspectConversionsEnforce          = new TAspectConversion[3];
            Array.Copy(AspectConversions, AspectConversionsEnforce, 3);
            if (preview != null)
            {
                PreviewViewmodel = new PreviewViewmodel(engine, preview)
                {
                    SelectedIngestOperation = operation
                }
            }
            ;
        }
Example #3
0
 public override void Remove(IPreview frameEditor)
 {
     foreach (var dc in Components)
     {
         dc.Remove(frameEditor);
     }
 }
Example #4
0
 public override void Remove(IPreview frameEditor)
 {
     if (_line != null)
     {
         frameEditor.Canva.Children.Remove(_line);
     }
 }
Example #5
0
        public void Start(Control sourceControl, Effects.Effects effects, Point location, IPreview preview)
        {
            if (IsDisposed)
            {
                return;
            }

            if (!IsHandleCreated)
            {
                CreateHandle();
            }

            _effects = effects;

            SourceControl = sourceControl ?? throw new ArgumentNullException(nameof(sourceControl));

            IsDragging = true;
            Location   = location;

            Preview                  = preview;
            UpdatablePreview         = preview as IUpdatablePreview;
            PreviewOpacityController = preview as IPreviewOpacityController;

            if (UpdatablePreview is object)
            {
                UpdatablePreview.Updated += OnUpdatablePreviewUpdated;
                UpdatablePreview?.Start();
            }

            InvalidatePreview();

            _effects.StartEffect.Start(new IEffect.Arguments(this, SourceControl, null));
        }
Example #6
0
        public static IPreview CreatePreview(IOutlet <object> outlet)
        {
            IPreview preview = null;

            if (outlet is IOutlet <MatrixWorld> )
            {
                preview = new MatrixPreview();
            }
            else if (outlet is IOutlet <TransitionsList> )
            {
                preview = new ObjectsPreview();
            }
            else if (outlet is IOutlet <SplineSys> )
            {
                preview = new SplinePreview();
            }
            else
            {
                return(null);
            }

            if (all.ContainsKey(outlet))
            {
                all[outlet] = preview;
            }
            else
            {
                all.Add(outlet, preview);
            }

            return(preview);
        }
Example #7
0
        public MediaSearchViewmodel(IPreview preview, IEngine engine, TMediaType mediaType, VideoLayer layer,
                                    bool closeAfterAdd, VideoFormatDescription videoFormatDescription)
        {
            _engine = engine;
            Layer   = layer;
            if (mediaType == TMediaType.Movie)
            {
                _videoFormatDescription = engine.FormatDescription;
                if (preview != null)
                {
                    PreviewViewmodel = new PreviewViewmodel(engine, preview)
                    {
                        IsSegmentsVisible = true
                    }
                }
                ;
            }
            else
            {
                _videoFormatDescription = videoFormatDescription;
            }
            _mediaType = mediaType;
            if (PreviewViewmodel != null)
            {
                PreviewViewmodel.PropertyChanged += _onPreviewViewModelPropertyChanged;
            }
            IMediaDirectory pri = mediaType == TMediaType.Animation
                ? (IMediaDirectory)engine.MediaManager.AnimationDirectoryPRI
                : engine.MediaManager.MediaDirectoryPRI;
            IMediaDirectory sec = mediaType == TMediaType.Animation
                ? (IMediaDirectory)engine.MediaManager.AnimationDirectorySEC
                : engine.MediaManager.MediaDirectorySEC;

            _searchDirectory = pri != null && pri.DirectoryExists()
                ? pri
                : sec != null && sec.DirectoryExists()
                    ? sec
                    : null;
            if (_searchDirectory != null)
            {
                _searchDirectory.MediaAdded    += _searchDirectory_MediaAdded;
                _searchDirectory.MediaRemoved  += _searchDirectory_MediaRemoved;
                _searchDirectory.MediaVerified += _searchDirectory_MediaVerified;
            }
            _mediaCategory    = MediaCategories.FirstOrDefault();
            NewEventStartType = TStartType.After;
            if (!closeAfterAdd)
            {
                OkButtonText = resources._button_Add;
            }
            _createCommands();
            Items = new ObservableCollection <MediaViewViewmodel>(_searchDirectory.GetFiles()
                                                                  .Where(m => _canAddMediaToCollection(m, mediaType))
                                                                  .Select(m => new MediaViewViewmodel(m)));
            _itemsView = CollectionViewSource.GetDefaultView(Items);
            _itemsView.SortDescriptions.Add(mediaType == TMediaType.Movie
                ? new SortDescription(nameof(MediaViewViewmodel.LastUpdated), ListSortDirection.Descending)
                : new SortDescription(nameof(MediaViewViewmodel.MediaName), ListSortDirection.Ascending));
            _itemsView.Filter += _itemsFilter;
        }
Example #8
0
 public static IPreview GetInstance(string extname)
 {
     if (!_instance.ContainsKey(extname))
     {
         lock (lockHelper)
         {
             if (!_instance.ContainsKey(extname))
             {
                 IPreview value = null;
                 try
                 {
                     var name = string.Format("BBX.Plugin.Preview.{0}.Viewer, BBX.Plugin.Preview.{0}", extname);
                     var type = Type.GetType(name, false, true);
                     if (type != null)
                     {
                         value = (IPreview)Activator.CreateInstance(type);
                     }
                 }
                 catch
                 {
                     value = null;
                 }
                 _instance.Add(extname, value);
             }
         }
     }
     return((IPreview)_instance[extname]);
 }
 public ScrollSynchronizer(ILogger logger, IWorkingContentEditorsProvider contentEditorsProvider, IPreview preview) : base(logger)
 {
     _contentEditorsProvider = contentEditorsProvider;
     _preview = preview;
     Initialize();
     HookEvents();
 }
Example #10
0
 public CreateInvoice(ICustomerManager getCustomers, IGetUsedServices getUsedServices, IGetPrice getPrice, IPreview preview)
 {
     _getCustomers    = getCustomers;
     _getUsedServices = getUsedServices;
     _getPrice        = getPrice;
     _preview         = preview;
 }
Example #11
0
        public static BaseMatrixWindow GetCreateWindow(IPreview preview)
        /// Tries to find opened window by preview and updates it, and opens new window if non is found
        {
            IOutlet <object> outlet = PreviewManager.GetOutlet(preview);

            Guid previewGuid = outlet.Gen.Guid;

            BaseMatrixWindow[] windows = Resources.FindObjectsOfTypeAll <BaseMatrixWindow>();

            BaseMatrixWindow window = null;

            for (int i = 0; i < windows.Length; i++)
            {
                if (windows[i] is IPreviewWindow serGuid && serGuid.SerializedGenGuid == previewGuid)
                {
                    window = windows[i]; break;
                }
            }

            if (window == null)
            {
                window = preview.CreateWindow();
                if (window is IPreviewWindow serGuid)
                {
                    serGuid.SerializedGenGuid = previewGuid;
                }
                window.ShowTab();
            }

            window.Show();

            return(window);
        }
Example #12
0
        private static void TerrainWindowButtons(IPreview preview)
        {
            using (Cell.LineStd)
            {
                using (Cell.RowPx(20))
                {
                    if (preview.Terrain != null)
                    {
                        if (Draw.Button(UI.current.textures.GetTexture("MapMagic/Icons/PreviewToTerrainActive"), visible: false))
                        {
                            PreviewManager.RemoveAllFromTerrain();
                        }
                    }
                    else
                    {
                        if (Draw.Button(UI.current.textures.GetTexture("MapMagic/Icons/PreviewToTerrain"), visible: false))
                        {
                            PreviewManager.RemoveAllFromTerrain();
                            TerrainTile previewTile = GraphWindow.current.mapMagic?.PreviewTile;
                            preview.ToTerrain(previewTile?.main?.terrain, previewTile?.draft?.terrain);
                        }
                    }
                }

                using (Cell.RowPx(20))
                    if (Draw.Button(UI.current.textures.GetTexture("MapMagic/Icons/PreviewToWindow"), visible: false))
                    {
                        PreviewManager.GetCreateWindow(preview);
                    }

                //Cell.EmptyRow();
            }
        }
 public MediaSearchViewmodel(IPreview preview, IEngine engine, TMediaType mediaType, VideoLayer layer,
                             bool closeAfterAdd, VideoFormatDescription videoFormatDescription)
 {
     Engine = engine;
     Layer  = layer;
     if (mediaType == TMediaType.Movie)
     {
         _videoFormatDescription = engine.FormatDescription;
         if (preview != null)
         {
             _preview = new PreviewViewmodel(preview, false, false)
             {
                 IsSegmentsVisible = true
             }
         }
         ;
     }
     else
     {
         _videoFormatDescription = videoFormatDescription;
     }
     _mediaType = mediaType;
     if (_preview != null)
     {
         _preview.PropertyChanged += _onPreviewViewModelPropertyChanged;
     }
     CommandAdd        = new UiCommand(_add, _allowAdd);
     _mediaCategory    = MediaCategories.FirstOrDefault();
     NewEventStartType = TStartType.After;
     SetupSearchDirectory(closeAfterAdd, mediaType);
 }
Example #14
0
 public override void QuickRender(IPreview frameEditor)
 {
     foreach (var dc in Components)
     {
         dc.QuickRender(frameEditor);
     }
 }
        public MediaSearchViewmodel(IPreview preview, IMediaManager manager, TMediaType mediaType, VideoLayer layer, bool closeAfterAdd, VideoFormatDescription videoFormatDescription)
        {
            _manager = manager;
            _engine  = manager.Engine;
            Layer    = layer;
            if (mediaType == TMediaType.Movie)
            {
                _videoFormatDescription = manager.FormatDescription;
                _frameRate = _videoFormatDescription.FrameRate;
                if (preview != null)
                {
                    _previewViewmodel = new PreviewViewmodel(preview)
                    {
                        IsSegmentsVisible = true
                    }
                }
                ;
                WindowWidth = _previewViewmodel != null ? 950 : 650;
            }
            else
            {
                _videoFormatDescription = videoFormatDescription;
                _frameRate  = videoFormatDescription?.FrameRate;
                WindowWidth = 750;
            }
            _mediaType = mediaType;
            if (_previewViewmodel != null)
            {
                _previewViewmodel.PropertyChanged += _onPreviewViewModelPropertyChanged;
            }
            IMediaDirectory pri = mediaType == TMediaType.Animation ? (IMediaDirectory)_manager.AnimationDirectoryPRI : _manager.MediaDirectoryPRI;
            IMediaDirectory sec = mediaType == TMediaType.Animation ? (IMediaDirectory)_manager.AnimationDirectorySEC : _manager.MediaDirectorySEC;

            _searchDirectory                = pri != null && pri.DirectoryExists() ? pri : sec != null && sec.DirectoryExists() ? sec : null;
            _searchDirectory.MediaAdded    += _searchDirectory_MediaAdded;
            _searchDirectory.MediaRemoved  += _searchDirectory_MediaRemoved;
            _searchDirectory.MediaVerified += _searchDirectory_MediaVerified;

            _closeAfterAdd    = closeAfterAdd;
            _mediaCategory    = MediaCategories.FirstOrDefault();
            NewEventStartType = TStartType.After;
            if (!closeAfterAdd)
            {
                OkButtonText = resources._button_Add;
            }
            _createCommands();
            _items = new ObservableCollection <MediaViewViewmodel>(_searchDirectory.GetFiles()
                                                                   .Where(m => _canAddMediaToCollection(m, mediaType))
                                                                   .Select(m => new MediaViewViewmodel(m)));
            _itemsView = CollectionViewSource.GetDefaultView(_items);
            _itemsView.SortDescriptions.Add(new SortDescription(nameof(MediaViewViewmodel.MediaName), ListSortDirection.Ascending));
            _itemsView.Filter += _itemsFilter;
            _view              = new MediaSearchView()
            {
                DataContext = this
            };
            _view.Closed += _windowClosed;
            _view.Show();
        }
        void IPreviewService.Show(IPreview preview)
        {
            var previewControl = preview as Control;

            previewControl.Dock   = DockStyle.Fill;
            previewControl.Parent = hostPanel;
            previewControl.BringToFront();
        }
        private async void StopPreview()
        {
            if (preview != null)
            {
                await preview.stop();
            }

            preview = null;
        }
Example #18
0
        public static void SetObjectsAll(TileData data)
        {
            foreach (var kvp in all)
            {
                IOutlet <object> outlet  = kvp.Key;
                IPreview         preview = kvp.Value;

                preview.SetObject(outlet, data);
            }
        }
Example #19
0
 public IngestEditorViewmodel(IList <IIngestOperation> convertionList, IPreview preview, IEngine engine)
 {
     _engine           = engine;
     OperationList     = new ObservableCollection <IngestOperationViewModel>(convertionList.Select(op => new IngestOperationViewModel(op, preview, engine)));
     SelectedOperation = OperationList.FirstOrDefault();
     foreach (var c in OperationList)
     {
         c.PropertyChanged += _convertOperationPropertyChanged;
     }
     CommandDeleteOperation = new UiCommand(_deleteOperation);
 }
Example #20
0
 public static IOutlet <object> GetOutlet(IPreview preview)
 {
     foreach (var kvp in all)
     {
         if (kvp.Value == preview)
         {
             return(kvp.Key);
         }
     }
     return(null);
 }
 public PreviewViewmodel(IPreview preview)
 {
     preview.PropertyChanged += this.PreviewPropertyChanged;
     _channelPRV              = preview.PlayoutChannelPRV;
     if (_channelPRV != null)
     {
         _channelPRV.PropertyChanged += this.OnChannelPropertyChanged;
     }
     _preview           = preview;
     _formatDescription = _preview.FormatDescription;
     CreateCommands();
 }
Example #22
0
        public override void Remove(IPreview frameEditor)
        {
            if (_image != null)
            {
                frameEditor.Canva.Children.Remove(_image);
            }

            if (_border != null)
            {
                frameEditor.Canva.Children.Remove(_border);
            }
        }
Example #23
0
        private void _initDc(IPreview frameEditor)
        {
            if (!frameEditor.Canva.Children.Contains(_image))
            {
                frameEditor.Canva.Children.Add(_image);
            }

            if (!frameEditor.Canva.Children.Contains(_border))
            {
                frameEditor.Canva.Children.Add(_border);
            }
        }
Example #24
0
 public IngestEditViewmodel(IList <IConvertOperation> convertionList, IPreview preview, IMediaManager mediaManager) : base(convertionList, new Views.IngestEditorView(), resources._window_IngestAs)
 {
     _conversionList   = new ObservableCollection <ConvertOperationViewModel>(from op in convertionList select new ConvertOperationViewModel(op, preview, mediaManager));
     SelectedOperation = _conversionList.FirstOrDefault();
     foreach (var c in _conversionList)
     {
         c.PropertyChanged += _convertOperationPropertyChanged;
     }
     CommandDeleteOperation = new UICommand {
         ExecuteDelegate = _deleteOperation
     };
     OkCancelButtonsActivateViaKeyboard = false;
 }
Example #25
0
 public PreviewViewmodel(IPreview preview, bool canTrimMedia, bool showStillButtons)
 {
     _showStillButtons           = showStillButtons;
     preview.PropertyChanged    += PreviewPropertyChanged;
     preview.StillImageLoaded   += Preview_StillImageLoaded;
     preview.StillImageUnLoaded += Preview_StillImageUnLoaded;
     HaveLiveDevice              = preview.HaveLiveDevice;
     _loadedStillImages          = new Dictionary <VideoLayer, IMedia>(preview.LoadedStillImages);
     _preview          = preview;
     FormatDescription = VideoFormatDescription.Descriptions[preview.VideoFormat];
     _canTrimMedia     = canTrimMedia;
     CreateCommands();
 }
Example #26
0
 public PreviewViewmodel(IEngine engine, IPreview preview)
 {
     preview.PropertyChanged += PreviewPropertyChanged;
     _channel = preview.PlayoutChannelPRV;
     if (_channel != null)
     {
         _channel.PropertyChanged += OnChannelPropertyChanged;
     }
     _engine            = engine;
     _preview           = preview;
     _formatDescription = _preview.FormatDescription;
     CreateCommands();
 }
Example #27
0
        public override void QuickRender(IPreview frameEditor)
        {
            if (_scalePreview == null)
            {
                _scalePreview = new ScaleTransform();
            }

            _scalePreview.CenterX = frameEditor.CenterX;
            _scalePreview.CenterY = frameEditor.CenterY;

            _scalePreview.ScaleX = frameEditor.ZoomEngine.Scale;
            _scalePreview.ScaleY = frameEditor.ZoomEngine.Scale;

            if (_translatePreview == null)
            {
                _translatePreview = new TranslateTransform();
            }

            _translatePreview.X = frameEditor.CenterX * frameEditor.ZoomEngine.Scale;
            _translatePreview.Y = frameEditor.CenterY * frameEditor.ZoomEngine.Scale;

            if (_border != null)
            {
                _border.SetValue(RenderOptions.EdgeModeProperty, SdeAppConfiguration.UseAliasing ? EdgeMode.Aliased : EdgeMode.Unspecified);
                _border.BorderBrush = _getBorderBrush();
                _border.Background  = _getBorderBackgroundBrush();

                if (_image.Source == null)
                {
                    _border.BorderThickness = new Thickness(0);
                    _border.Width           = 0;
                    _border.Height          = 0;
                }
                else
                {
                    double scaleX = Math.Abs(1d / (frameEditor.ZoomEngine.Scale * _scale.ScaleX));
                    double scaleY = Math.Abs(1d / (frameEditor.ZoomEngine.Scale * _scale.ScaleY));

                    if (double.IsInfinity(scaleX) || double.IsNaN(scaleX) ||
                        double.IsInfinity(scaleY) || double.IsNaN(scaleY))
                    {
                        _border.Width  = 0;
                        _border.Height = 0;
                    }
                    else
                    {
                        _border.BorderThickness = new Thickness(scaleX, scaleY, scaleX, scaleY);
                    }
                }
            }
        }
        public static bool BuildPreview(string temporaryDirectory, string sourceFile, string mimetype, int width, int height, out string previewMimetype, out string previewPath, out string error)
        {
            IPreview preview = null;
            bool     success = false;

            previewMimetype = null;
            previewPath     = null;
            error           = null;

            if (mimetype.StartsWith("image/") || mimetype.StartsWith("video/") || mimetype.StartsWith("audio/"))
            {
                preview = new ImageVideoPreview(temporaryDirectory);
            }
            else if (Pdf.PdfService.IsPdfCompatible(mimetype))
            {
                preview = new PdfPreview(temporaryDirectory);
            }
            else if (mimetype == "text/uri-list")
            {
                preview = new UrlPreview(temporaryDirectory);
            }
            else if (mimetype.StartsWith("text/plain"))
            {
                preview = new TextPreview(temporaryDirectory);
            }

            if (preview != null)
            {
                PreviewFormat format;
                previewPath = preview.Process(sourceFile, mimetype, width, height, out format, out error);
                if (previewPath != null)
                {
                    if (format == PreviewFormat.PNG)
                    {
                        previewMimetype = "image/png";
                    }
                    else
                    {
                        previewMimetype = "image/jpeg";
                    }
                    success = true;
                }
                else
                {
                    success = false;
                }
            }
            return(success);
        }
        public static void DrawPreview(IOutlet <object> outlet)
        {
            IPreview preview = PreviewManager.GetPreview(outlet);

            if (preview == null)
            {
                preview = PreviewManager.CreatePreview(outlet);
                if (preview == null)
                {
                    return;                                  //for unknown types
                }
                preview.SetObject(outlet, GraphWindow.current.mapMagic?.PreviewData);
            }

            //preview itself
            using (Cell.Full)
            {
                Color backColor = StylesCache.isPro ?
                                  new Color(0.33f, 0.33f, 0.33f, 1) :
                                  new Color(0.4f, 0.4f, 0.4f, 1);
                Draw.Rect(BackgroundColor);                  //background in case no preview, or preview object was not assigned

                if (preview != null)
                {
                    preview.DrawInGraph();
                }
            }

            //clock/na
            if (GraphWindow.current.mapMagic == null)
            {
                using (Cell.Full) Draw.Icon(UI.current.textures.GetTexture("MapMagic/PreviewNA"));
            }
            else if (preview.Stage == PreviewStage.Generating || (preview.Stage == PreviewStage.Blank && GraphWindow.current.mapMagic.IsGenerating()))
            {
                using (Cell.Full) Draw.Icon(UI.current.textures.GetTexture("MapMagic/PreviewSandClock"));
            }
            else if (preview.Stage == PreviewStage.Blank)
            {
                using (Cell.Full) Draw.Icon(UI.current.textures.GetTexture("MapMagic/PreviewNA"));
            }

            //terrain buttons
            if (preview != null)
            {
                using (Cell.Full)
                    TerrainWindowButtons(preview);
            }
        }
Example #30
0
        public override void DoAction(string path, FileType parFileType, frmMain frm)
        {
            System.Threading.Thread tt = new System.Threading.Thread(delegate()
            {
                try
                {
                    if (FileExists(path))
                    {
                        if (parFileType.PreviewType == null)
                        {
                            ShowError("Preview not available");
                        }
                        else
                        {
                            Type t       = parFileType.PreviewType;
                            Form f       = new Form();
                            Panel pnl    = new Panel();
                            pnl.Dock     = System.Windows.Forms.DockStyle.Fill;
                            pnl.Location = new System.Drawing.Point(0, 0);
                            pnl.Name     = "pnlPreview";
                            pnl.Size     = new System.Drawing.Size(96, 77);
                            pnl.TabIndex = 1;
                            f.Controls.Add(pnl);
                            if (pnl.Controls.Count > 0)
                            {
                                Control pOld = pnl.Controls[0];
                                pOld.Dispose();
                            }
                            pnl.Controls.Clear();
                            IPreview p = (IPreview)Activator.CreateInstance(t);
                            pnl.Controls.Add((Control)p);
                            ((Control)p).Dock = DockStyle.Fill;

                            f.Load += delegate(object sender, EventArgs e)
                            {
                                p.Preview(path);
                            };
                            Application.Run(f);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ShowError("An error occured while loading preview control");
                }
            });
            tt.SetApartmentState(System.Threading.ApartmentState.STA);
            tt.Start();
        }
Example #31
0
        /// <summary>
        /// Preview is handled internally and is turned on and off using IPreview interface.
        /// </summary>
        public override bool HasPreviewGUI()
        {
            foreach (object instance in Instances)
            {
                IPreview preview = instance as IPreview;
                if (preview == null || preview.Preview == null || preview.Preview.Length == 0)
                {
                    continue;
                }

                return(true);
            }

            return(false);
        }
        private void StartPreview() {
            int videoDevice = VideoSelect.SelectedIndex;
            int audioDevice = AudioSelect.SelectedIndex;

            if (videoDevice == -1 || audioDevice == -1) { 
                return; 
            }

            ResetEffects();

            UpdateUiState(PageState.None);

            string videoDeviceId = ((ComboBoxItem)VideoSelect.SelectedItem).Name.ToString();
            string audioDeviceId = ((ComboBoxItem)AudioSelect.SelectedItem).Name.ToString();

            MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings {                    
                    VideoDeviceId = videoDeviceId,
                    AudioDeviceId = audioDeviceId,
                    StreamingCaptureMode = StreamingCaptureMode.AudioAndVideo,
                };

            IAsyncOperation<IPreview> previewTask;

            previewTask = cameraCapture.createPreview(PreviewWindow, settings);
                       
            if (preview != null) {
                preview.start().AsTask().Wait();
            }

            previewTask.Completed = delegate {
                try {
                    preview = previewTask.GetResults();
                }
                catch (UnauthorizedAccessException) {
                    ShowMessageDialog(StringLoader.Get("Camera_Access_Denied"));
                    return;
                }

                preview.start().AsTask().Wait();

                UpdateUiState(PageState.Ready);
            };
        }
        private async void StopPreview() {
            if (preview != null) {
                await preview.stop();
            }

            preview = null;
        }