How to use the @iiif/vocabulary/dist-commonjs/.ExternalResourceType.SOUND function in @iiif/vocabulary

To help you get started, we’ve selected a few @iiif/vocabulary examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github edsilv / biiif / Utils.ts View on Github external
console.log(chalk.green('getting file dimensions for: ') + file);

        if (!Utils.isJsonFile(file)) {
            switch (type.toLowerCase()) {
                // if it's an image, get the width and height and add to the annotation body and canvas
                case ExternalResourceType.IMAGE :
                    const image: any = await Jimp.read(file);
                    const width: number = image.bitmap.width;
                    const height: number = image.bitmap.height;
                    canvasJson.width = Math.max(canvasJson.width || 0, width);
                    canvasJson.height = Math.max(canvasJson.height || 0, height);
                    annotationJson.body.width = width;
                    annotationJson.body.height = height;
                    break;
                // if it's a sound, get the duration and add to the canvas
                case ExternalResourceType.SOUND :
                case ExternalResourceType.VIDEO :
                    try {
                        const info: any = await ffprobe(file, { path: ffprobeStatic.path });
                        if (info && info.streams && info.streams.length) {
                            const duration: number = Number(info.streams[0].duration);
                            canvasJson.duration = duration;
                        }
                    } catch {
                        console.warn(`ffprobe couldn't load ${file}`);
                    }
                    
                    break;
            }
        }
    }