Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createVideo() callback could return instance of video #7468

Open
1 of 17 tasks
ffd8 opened this issue Jan 15, 2025 · 2 comments
Open
1 of 17 tasks

createVideo() callback could return instance of video #7468

ffd8 opened this issue Jan 15, 2025 · 2 comments

Comments

@ffd8
Copy link
Contributor

ffd8 commented Jan 15, 2025

Increasing access

Make this function more useful, which could have accessibility implications

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

Feature enhancement details

Was just testing loading an array of createVideo(), in which each one should be muted, looped and hidden, however I learned that the callback function doesn't include the instance of media to directly affect, rather it expects a single global variable is used. Perhaps this could return as a param the media instance, so that one can directly mute, hide, loop that video once loaded?

let videos = [
	'path1.mov',
	'path2.mov',
	'path3.mov',
	'path4.mov',
	]
	
let videoPlayers = []

function setup() {
	createCanvas(windowWidth, windowHeight)
	
	for(let v of videos){
		videoPlayers.push(createVideo('data/videos/' + v, (vid) => {
			print(vid) // *** undefined, but ideal if that was returned media item
			videoPlayers[videoPlayers.length-1].volume(0) // only works once, too fast on next call
			videoPlayers[videoPlayers.length-1].loop() // only works once, too fast on next call
			videoPlayers[videoPlayers.length-1].hide() // only works once, too fast on next call
			})
		)
	}
}
@ffd8
Copy link
Contributor Author

ffd8 commented Jan 15, 2025

Quick followup, of course this can be done without the callback by first preloading it – but a small modification would then require less code.

let videos = [
	'path1.mov',
	'path2.mov',
	'path3.mov',
	'path4.mov',
	]
	
let videoPlayers = []

function preload(){
	for(let v of videos){
		videoPlayers.push(createVideo('data/videos/' + v))
	}
}

function setup() {
	createCanvas(windowWidth, windowHeight)
	for(let vp of videoPlayers){
		vp.volume(0)
		vp.loop()
		vp.hide()
	}
}

@dhruvinjs
Copy link

Hey So, am new here would love to help you on fixing this issue here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants