npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zcomponent/three-video-player

v1.1.7

Published

HLS & MP4 Player for Mattercraft

Downloads

5

Readme

@zcomponent/three-video-player

This package adds support for video playback in 3D environments to the Mattercraft 3D content creation platform for the web. It allows you to easily integrate and control video content within your 3D scenes, supporting various video formats and transparency options.

Features

  • Supports both HLS (.m3u8) and MP4 video formats
  • Offers various video transparency types, including chroma key and side-by-side transparency
  • Provides control over video playback properties like volume, looping, and muting
  • Seamlessly integrates with the Mattercraft 3D environment

Getting Started

To use the VideoPlayer component in your Mattercraft project:

  1. Right-click on a Group node in your scene's Hierarchy.
  2. Navigate to the "Media" submenu.
  3. Select "VideoPlayer" to add it to your scene.

Video Formats

The VideoPlayer supports two primary video formats:

  • HLS (.m3u8): For adaptive streaming
  • MP4: For standard video playback

Transparency Options

The VideoPlayer offers three transparency types:

  1. None: Standard video playback without transparency
  2. Chroma Key: Removes a specific color from the video, typically used for green screen effects
  3. Side-by-Side: Uses a side-by-side video format where one side contains the alpha channel

Key Properties

  • source: The URL or file path of the video (supports .m3u8 and .mp4 files)
  • transparent: The type of transparency to apply (none, chromaKey, or sideBySide)
  • autoplay: Whether the video should start playing automatically
  • volume: The playback volume (0 to 1)
  • muted: Whether the video is muted
  • loop: Whether the video should loop when it reaches the end

Chroma Key Properties

When using chroma key transparency:

  • similarity: How closely a color must match the key color to be made transparent
  • smoothness: The smoothness of the chroma key edges
  • spill: Controls color spill reduction
  • keyColor: The color to be made transparent (default is green: [0, 1, 0])

Side-by-Side Properties

When using side-by-side transparency:

  • direction: The direction of the side-by-side split (LeftRight or TopBottom)
  • alphaFirst: Whether the alpha channel is on the left/top (true) or right/bottom (false)

Playback Control

The VideoPlayer provides several methods for controlling playback:

  • play(): Starts or resumes playback
  • pause(): Pauses playback
  • stop(): Stops playback and resets to the beginning
  • seek(time): Jumps to a specific time in the video (in milliseconds)

Events

The VideoPlayer emits several events that you can listen to:

  • onEnded: Fired when the video playback ends
  • onPause: Fired when the video is paused
  • onPlay: Fired when video playback starts
  • onPlaying: Fired when the video starts playing after being paused or stopped for buffering
  • onWaiting: Fired when the video stops because it needs to buffer the next frame
  • onError: Fired when an error occurs during video loading or playback

Example Usage

Here's a simple example of how to use the VideoPlayer in a custom behavior:

import { Behavior, ContextManager } from '@zcomponent/core';
import { VideoPlayer } from '@zcomponent/three-video-player';
/**
 * @zbehavior
 */
export class MyVideoBehavior extends Behavior<VideoPlayer> {
 constructor(contextManager: ContextManager, instance: VideoPlayer) {
  super(contextManager, instance);

  console.log(this.instance.length())

  // Listen for the video to end
  this.register(this.instance.onEnded, () => {
   console.log('Video playback ended');
  });
 }
}

Here's an example of dynamically creating a VideoPlayer component in a custom Three.js component:

import { Component, ContextManager, registerLoadable } from '@zcomponent/core';
import { Group } from '@zcomponent/three/lib/components/Group';
import { VideoPlayer, VideoTransparencyType } from '@zcomponent/three-video-player';

/**
 * @zcomponent
 */
export class CustomVideoComponent extends Group {
 private videoPlayer: VideoPlayer;

 constructor(contextManager: ContextManager, props: {}) {
  super(contextManager, {});

  // Create a new VideoPlayer instance
  const source = new URL('./path/to/your/video.mp4', import.meta.url).href;

  this.videoPlayer = new VideoPlayer(contextManager, {
   source,
   transparent: VideoTransparencyType.none,
   autoplay: false
  });

  // Add the VideoPlayer  to our Group
  this.appendChild(this.videoPlayer);

 }

 // Example method to start playback
 playVideo() {
  this.videoPlayer.play();
 }

 // Don't forget to clean up when the component is disposed
 dispose() {
  this.videoPlayer.dispose();
  return super.dispose();
 }
}