Exemplo n.º 1
0
        private void UpdateContentProperties()
        {
            //update content properties and reload the file (since header size might have changed)
            var contentProperties = _asfObjects.OfType <AsfFileHeaderItem>().First().Items.OfType <AsfContentDescriptionObjectItem>().FirstOrDefault();

            try
            {
                AsfFile.From(FileName)
                .WithAuthor(contentProperties.EditProperties.Single(x => x.Key == "Author").Value)
                .WithDescription(contentProperties.EditProperties.Single(x => x.Key == "Description").Value)
                .WithCopyright(contentProperties.EditProperties.Single(x => x.Key == "Copyright").Value)
                .WithTitle(contentProperties.EditProperties.Single(x => x.Key == "Title").Value)
                .WithRating(contentProperties.EditProperties.Single(x => x.Key == "Rating").Value)
                .Update();
                LoadFile(FileName);
            }
            catch (IOException)
            {
                FileErrorDetails.Clear();
                FileErrorDetails.Add(new FileErrorInfo()
                {
                    ErrorType = "Update Failed", ErrorDetails = "File is in use by another process"
                });


                Dispatcher.DelayInvoke(TimeSpan.FromMilliseconds(500),
                                       new Action(() =>
                {
                    ErrorDetailsVisible = true;
                    IsBusy = false;
                    RaisePropertyChanged("IsBusy");
                    RaisePropertyChanged("ErrorDetailsVisible");
                }));
            }
        }
Exemplo n.º 2
0
        private void LoadFile(string fileName)
        {
            FileErrorDetails.Clear();
            _asfObjects.Clear();
            TimeToImageConverter.EmptyCache();

            var asfItems = AsfInfo.GetHeaderObjects(fileName);

            if (asfItems == null) //invalid file
            {
                FileErrorDetails.Add(new FileErrorInfo()
                {
                    ErrorType = "Invalid ASF file", ErrorDetails = "No Header Object found"
                });
                Dispatcher.DelayInvoke(TimeSpan.FromMilliseconds(500),
                                       new Action(() =>
                {
                    ErrorDetailsVisible = true;
                    IsBusy = false;
                    RaisePropertyChanged("IsBusy");
                    RaisePropertyChanged("ErrorDetailsVisible");
                }));
            }
            else
            {
                foreach (AsfHeaderItem asfItem in asfItems)
                {
                    _asfObjects.Add(asfItem);
                }

                double fileLength = AsfHeaderItem.Configuration.Duration;
                HasVideoStream = AsfHeaderItem.Configuration.ImageWidth > 0;

                _previewImagesLoadedCount = 0;
                _previewImages.Clear();
                _loadingImages = new List <PreviewImage>();

                if (HasVideoStream)
                {
                    for (int i = 0; i < _thumbCount; i++)
                    {
                        double       startOffset = ((double)i / _thumbCount) * fileLength;
                        PreviewImage pi          = new PreviewImage()
                        {
                            FileName         = fileName,
                            TimeOffset       = startOffset,
                            DisplayTime      = (uint)(startOffset * 1000),
                            PresentationTime = (uint)(startOffset * 1000) + AsfHeaderItem.Configuration.AsfPreroll
                        };

                        Action a = new Action(pi.GenerateSource);
                        _loadingImages.Add(pi);
                        a.BeginInvoke(new AsyncCallback(PreviewImageLoaded), a);
                    }
                }

                RaisePropertyChanged("Title");
                Dispatcher.DelayInvoke(TimeSpan.FromMilliseconds(500),
                                       new Action(() =>
                {
                    IsBusy         = false;
                    IsFileLoaded   = true;
                    PreviewVisible = HasVideoStream;
                    RaisePropertyChanged("IsBusy");
                    RaisePropertyChanged("PreviewVisible");
                    RaisePropertyChanged("HasVideoStream");
                }));
            }
        }