Skip to content

createVideo() callback could return instance of video #7468

Closed
@ffd8

Description

@ffd8
Contributor

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
			})
		)
	}
}

Activity

ffd8

ffd8 commented on Jan 15, 2025

@ffd8
ContributorAuthor

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

dhruvinjs commented on Jan 15, 2025

@dhruvinjs

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

subCode321

subCode321 commented on Feb 28, 2025

@subCode321
Contributor

@ffd8 , I've put our a PR to make the changes

reopened this on Jun 4, 2025
ksen0

ksen0 commented on Jun 4, 2025

@ksen0
Member

@davepagurek I see the same pattern in 2.0 on p5.MediaElement:1324 - should I make the matching PR there?

davepagurek

davepagurek commented on Jun 4, 2025

@davepagurek
Contributor

That would be great, thanks!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @ffd8@ksen0@davepagurek@subCode321@dhruvinjs

      Issue actions

        createVideo() callback could return instance of video · Issue #7468 · processing/p5.js