Coder Social home page Coder Social logo

brunos3d / video-ambilight Goto Github PK

View Code? Open in Web Editor NEW
103.0 5.0 7.0 888 KB

๐ŸŒˆ Ambilight Effect - React - Next.js (YouTube iframe, Video + Canvas).

Home Page: https://brunos3d.github.io/video-ambilight/

License: MIT License

HTML 34.23% JavaScript 13.52% CSS 13.09% TypeScript 39.16%
html5 effect javascript css ambilight sample styles design event nextjs-conf clone nextjs fx

video-ambilight's Introduction

preview

Video Ambilight

๐ŸŒˆ ๐Ÿ’ป โœจ

HTML5 + JS - Ambilight Effect sample project (YouTube iframe, Video + Canvas).

๐Ÿงช About

This is a project that came about as an inspiration after the release of Next.js 11 during Nextjs Conf, where the video player on the presentation page had an ambilight effect.

๐Ÿš€ Preview

Video + Canvas

YouTube iframe

๐Ÿ–‹ CodePen

Video + Canvas

YouTube iframe

video-ambilight's People

Contributors

brunos3d avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

video-ambilight's Issues

the next version in the repo doesnt work

Unhandled Runtime Error
TypeError: event.target.getCurrentTime is not a function

Source
src\components\VideoAmbilight\index.tsx (43:42) @ getCurrentTime

  41 | 			switch (event.data) {
  42 | 				case PlayerStates.PLAYING:
> 43 | 					ambilightPlayer?.seekTo(event.target.getCurrentTime(), true)
     | 					                                    ^
  44 | 					ambilightPlayer?.playVideo()
  45 | 					break
  46 | 				case PlayerStates.PAUSED:

iframe API deprecated calls and position-sync bug

The "setPlaybackQuality" API call is a no-op. It was removed in October 2019.

Hence the whole optimizeAmbient function is pointless. The ambient video can be muted in the "onReady" callback once.

The requestAnimationFrame function is also a no-op since it gets started before both objects are ready, then it throws an error and never executes again. Even if you fix that, ambient video stutters like crazy and never really plays, since it's overwhelmed with 60-240 seek calls per second. I've tried using regular "setInterval" at 1000ms and then only updating if both positions are too far apart, and it regularly makes the ambient video stutter. The best solution was not to do it at all.

Here is my entire version

function onYouTubeIframeAPIReady () {

	const el = document.getElementById ( 'video' );
	const videoId = el.dataset.ytId;

	const ambilight = new YT.Player ( 'ambilight', {
		videoId,
		events: {
			onReady: event => { event.target.mute (); }
		}
	});

	const video = new YT.Player ( 'video', {
		videoId,
		events: {
			onStateChange: event => {
				if ( event.data == YT.PlayerState.PLAYING ) {
					ambilight.seekTo ( event.target.getCurrentTime () );
					ambilight.playVideo ();
				} else if ( event.data == YT.PlayerState.PAUSED ) {
					ambilight.pauseVideo ();
					ambilight.seekTo ( event.target.getCurrentTime () );
				}
			}
		}
	});
}

It takes the videoId from the dataset of the "video" element.

e.g. <div id="video" data-yt-id="ASzOzrB-a9E"></div>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.