Skip to content

Xaval v0.7

Pre-release
Pre-release
Compare
Choose a tag to compare
@habbes habbes released this 28 Jun 21:34
· 29 commits to master since this release
e3a202c

Xaval v0.7 Release

Here's an overview of what's new:

  • support for importing and working with videos and other file types
  • the app has a new domain: https://xaval.app
  • other minor changes and bug fixes

Support for more file types

screen shot 2018-06-29 at 00 31 40

The file library now allows you to import videos and other file types from the local system and new APIs have been introduced to make it easy to work with them. The file library detects and sets the correct type of the file automatically when being imported. The library treats images, videos and other file types differently.

Video

Once you've imported a video file, you can use files.readVideo(name) to read the video. This returns a Video object, which is a wrapper around the underlying video. Like Camera, Video implements the VideoSource interface, which means it provides the same methods for reading frames (video.read) and obtaining a stream video.getStream(opts). But it also provides more methods and properties not available for camera objects:

const video = files.readVideo('scene');
const stream = video.getStream({ fps: 30 });
stream.pipe(imageViewer);
video.looping = true;
video.play();
setTimeout(() => video.pause(), 1000);
setTimeout(() => video.currentTime = 0, 2000);
setTimeout(() => video.play(), 3000);
setTimeout(() => video.stop(), 5000);

Like camera.stop(), video.stop() also stops and releases the attached stream.

Video API

Like Camera, Video has the following methods and properties from VideoSource:

  • video.width
  • video.height
  • video.read()
  • video.getStream(opts)

In addition, it implements the following:

Member Descritpion
video.duration: number gets the duration of the video in seconds
video.looping: boolean gets or sets whether the video is looping
video.playing: boolean gets whether or not video is playing
video.ended: boolean gets whether or not video has ended
video.currentTime: number gets or sets the current time of the video in seconds
video.play() plays the video, if there's a created from the video with autoStart to true, it will be started as well
video.pause() pauses the video. Also pauses the attached stream, if any, but does not release it. The video (and the stream) can be resumed again by calling video.play()
video.stop() stops the video and releases the attached stream, if any. To get another stream, you must call video.getStream()

Note: the fps option passed to getStream() determines only the rate at which the stream will read a frame from the video, and not the rate at which the video plays.

Other file types

For files other than videos and images, the file library provides files.getReader(filename), which returns a BinaryFileReader. This is a wrapper around the file blob that allows you to asynchronously read the file contents either as text, array buffer or data url.

const file = files.getReader('somefile');
file.readText().then(text => console.log(text));
file.readBuffer().then(buffer => console.log(buffer));
file.readDataURL().then(dataUrl => console.log(dataUrl));

BinaryFileReader API

Member Description
url: string the object url of the file
reader.readText(): Promise<string> reads the file contents as text
reader.readDataURL(): Promise<string> reads the file contents as a data url
reader.readBuffer(): Promise<ArrayBuffer> reads the file contents into an array buffer

Extended FileLibrary API

Here are new methods added to the FileLibrary API

Member Description
files.addVideo(url: string, filename?: string) adds a new video to the library from the specified source url. If filename is provided, it will be used as the name of the file in the library, an error will occur if the name already exists.
files.readVideo(filename: string): Video gets the video from the library. Every time this is called, it returns the same video object, not a new one like how files.readImage() works.
files.addBinary(file: Blob, filename?: string) adds a new file to the library (non-video and non-image).
files.getReader(filename: string): BinaryFileReader gets a reader for the specified file

Minor changes

  • widgets updates are not triggered if some inputs or params are not set (i.e. are undefined)
  • app shows confirmation dialog when closing to prevent user from accidentally closing app and losing work
  • the import button has been slightly tweaked
  • google analytics integration added to get insights on app usage

Bug fixes

  • files.rename() shows error when trying to rename a file that does not exist
  • files.addImage() now correctly applies the custom name (if provided) to the file tile
  • files.addImage() now checks for collisions and shows error if specified name already exists
  • widgets controls are now updated when the param value is programmatically set using widget.setParam()
  • fix bug causing slider control to display value 100 when the initial value was set to a number > 100