Pausing videos from your code

GoDAM for WooCommerce v2.7.0 Updated: 2026-11-05

GoDAM 2.7 can pause or mute videos when they leave the visitor’s view (see When a video goes out of view). This page is for sites that start, stop or listen to GoDAM videos from their own code: a custom carousel, a play button outside the player, or analytics that track pauses.

All examples use window.GoDAMAPI, which is ready once the godamAllPlayersReady event has fired. See the GoDAM Developer SDK for the basics.

GoDAMAPI.pauseAll() pauses every playing GoDAM video on the page. It works whatever the site’s out-of-view setting is, including Do nothing, so you can stop videos on inactive slides without turning the setting on.

// Swiper: when the slide changes, pause the videos on every other slide.
swiper.on( 'slideChange', () => {
	window.GoDAMAPI.pauseAll( {
		within: swiper.el,
		except: swiper.slides[ swiper.activeIndex ],
	} );
} );
OptionWhat it does
withinOnly pause videos inside this element or CSS selector. Leave it out to pause every video on the page.
exceptKeep these videos playing. Pass an element (a player, or a slide that holds one), an attachment ID, a Player instance, or an array of them.

It returns the number of videos it paused.

These pauses count as automatic. An autoplaying video starts again when the visitor comes back to its slide; a video the visitor started stays paused until they press play. CTA and form layers set to show on pause don’t appear.

The same works with any slider: call pauseAll() from its slide-change event (Slick’s afterChange, Splide’s moved, and so on).

Starting a video from your own button

GoDAM treats playback started from code as autoplay, so with the out-of-view setting on, it pauses when the video leaves the view and resumes when it’s back. When the visitor pressed your button, say so with userStarted, and the video follows the site’s setting for videos the visitor started.

const player = window.GoDAMAPI.getPlayer( '1641' );

document.querySelector( '#watch-now' ).addEventListener( 'click', () => {
	player.play( { userStarted: true } );
} );

Telling automatic pauses apart

The pause event now says why the video paused, so your analytics or UI can ignore pauses the visitor didn’t make.

player.on( 'pause', ( data ) => {
	if ( data?.reason ) {
		return; // 'visibility' (left the view) or 'api' (pauseAll)
	}
	// The visitor paused the video.
} );
reasonPaused by
'visibility'GoDAM, because the video left the view
'api'GoDAMAPI.pauseAll()
nullThe visitor, or your own player.pause() call

Scripts that run their own playback

If your script plays and stops GoDAM videos itself (a playlist, an auto-advancing slider, a modal), use window.godamVisibilityManager to keep it in step with GoDAM. It exists only on GoDAM 2.7 and later, so check each method before you call it. Each method takes a Video.js player: videojs.getPlayer( videoElement ).

MethodUse it when
markInteraction( player )The visitor started this video through your own UI, such as opening it in your modal.
resetInteraction( player )You hand the video back to an automatic preview, such as when your modal closes.
cancelResume( player )You stopped the video on purpose, so GoDAM shouldn’t start it again when it’s back in view.
isInView( player )Before you call play(), to skip videos that are hidden.
isAutomaticChange( player )Inside a pause or volumechange listener, to ignore pauses and mutes GoDAM made.
const vm = window.godamVisibilityManager;
const player = window.videojs.getPlayer( videoElement );

// Your slider moved on: stop the old slide for good.
player.pause();
vm?.cancelResume?.( player );

Players without controls always count as autoplaying, because the visitor can’t play or unmute them.

If your site already pauses videos

If your theme or plugin already pauses videos on scroll or on a browser tab switch, leave When a video goes out of view on Do nothing, so the two don’t act on the same video. pauseAll() still works.