コード例 #1
0
        public static BaseMetadata read(String location, MetadataFactory.ReadOptions options, CancellationToken token, int timeoutSeconds)
        {
            BaseMetadata metadata = new UnknownMetadata(FileUtils.getPathWithoutFileName(location));

            metadata.Name = Path.GetFileName(location);

            Logger.Log.Info("Reading metadata for: " + location);

            int timeoutMs = timeoutSeconds * 1000;

            Stream data = FileUtils.waitForFileAccess(location, FileAccess.Read, timeoutMs, token);

            MediaProbe mediaProbe = new MediaProbe();

            try
            {
                mediaProbe.open(location, token);

                switch (mediaProbe.MediaType)
                {
                case MediaType.AUDIO_MEDIA:
                {
                    metadata = new AudioMetadata(location, data);
                    AudioFileMetadataReader reader = new AudioFileMetadataReader();
                    reader.readMetadata(mediaProbe, data, options, metadata, token, timeoutSeconds);
                    break;
                }

                case MediaType.IMAGE_MEDIA:
                {
                    metadata = new ImageMetadata(location, data);
                    ImageFileMetadataReader reader = new ImageFileMetadataReader();
                    reader.readMetadata(mediaProbe, data, options, metadata, token, timeoutSeconds);
                    break;
                }

                case MediaType.VIDEO_MEDIA:
                {
                    metadata = new VideoMetadata(location, data);
                    VideoFileMetadataReader reader = new VideoFileMetadataReader();
                    reader.readMetadata(mediaProbe, data, options, metadata, token, timeoutSeconds);
                    break;
                }

                default:
                    break;
                }

                FileInfo info = new FileInfo(location);
                info.Refresh();

                if (info.Attributes.HasFlag(FileAttributes.ReadOnly))
                {
                    metadata.IsReadOnly = true;
                }

                if (!options.HasFlag(MetadataFactory.ReadOptions.LEAVE_STREAM_OPENED_AFTER_READ))
                {
                    metadata.close();
                }
            }
            catch (Exception e)
            {
                metadata.MetadataReadError = e;
            }
            finally
            {
                mediaProbe.close();
                mediaProbe.Dispose();
            }

            return(metadata);
        }
コード例 #2
0
        public static BaseMetadata read(String location, MetadataFactory.ReadOptions options, CancellationToken token, int timeoutSeconds)
        {
            BaseMetadata metadata = new UnknownMetadata(FileUtils.getPathWithoutFileName(location));
            metadata.Name = Path.GetFileName(location);

            Logger.Log.Info("Reading metadata for: " + location);

            int timeoutMs = timeoutSeconds * 1000;

            Stream data = FileUtils.waitForFileAccess(location, FileAccess.Read, timeoutMs, token);

            MediaProbe mediaProbe = new MediaProbe();

            try
            {
                mediaProbe.open(location, token);

                switch (mediaProbe.MediaType)
                {
                    case MediaType.AUDIO_MEDIA:
                        {
                            metadata = new AudioMetadata(location, data);                          
                            AudioFileMetadataReader reader = new AudioFileMetadataReader();
                            reader.readMetadata(mediaProbe, data, options, metadata, token, timeoutSeconds);
                            break;
                        }
                    case MediaType.IMAGE_MEDIA:
                        {
                            metadata = new ImageMetadata(location, data);                        
                            ImageFileMetadataReader reader = new ImageFileMetadataReader();
                            reader.readMetadata(mediaProbe, data, options, metadata, token, timeoutSeconds);
                            break;
                        }                
                    case MediaType.VIDEO_MEDIA:
                        {
                            metadata = new VideoMetadata(location, data);                       
                            VideoFileMetadataReader reader = new VideoFileMetadataReader();
                            reader.readMetadata(mediaProbe, data, options, metadata, token, timeoutSeconds);
                            break;
                        }
                    default:
                        break;
                }                

                FileInfo info = new FileInfo(location);
                info.Refresh();

                if (info.Attributes.HasFlag(FileAttributes.ReadOnly))
                {
                    metadata.IsReadOnly = true;
                }

                if (!options.HasFlag(MetadataFactory.ReadOptions.LEAVE_STREAM_OPENED_AFTER_READ))
                {
                    metadata.close();
                }

            }
            catch (Exception e)
            {
                metadata.MetadataReadError = e;                
            }
            finally
            {                
                mediaProbe.close();
                mediaProbe.Dispose();                
            }
                        
            return metadata;
        }