Play a sound when clicking on a marker

[ad_1]

Only if you handle the click event manually through js and run some code to play the sound.

Thank you for your reply.
Could you briefly tell me the code I can use?
I’ve tried this and that, but it doesn’t work.

You can try this code below. It’s just a sample. Note: each marker can store a data (see marker properties), we can use this field for mp3 URL or other logic. In my example I echo this field value (marker.data) to the browser console.


const plugin = this;
const $ = jQuery;

plugin.$container.on('click', '.ipnrm-marker', (e) => {
    const $marker = $(e.currentTarget);
    const markerId = $marker.attr('data-marker-id');
    const scene = plugin.viewer.sceneActive;
    
    if(scene) {
        const marker = scene.cfg.markers.find(x => x.id === markerId);
        if(marker) {
            console.log(marker.data);
            const audio = new Audio('https://assets.mixkit.co/active_storage/sfx/940/940-preview.mp3');
            audio.play();
        }
    }
});

It works perfectly.
Thanks. I appreciate your help.

  • This reply was modified 3 minutes ago by donsign.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer