• Resolved donsign

    (@donsign)


    Is there a way to make a specific sound play when a marker is clicked?
    I think it would be possible using Custom JS code, but I don’t know because I’m a beginner developer.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Avirtum

    (@avirtum)

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

    Thread Starter donsign

    (@donsign)

    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.

    Plugin Author Avirtum

    (@avirtum)

    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();
            }
        }
    });
    Thread Starter donsign

    (@donsign)

    It works perfectly.
    Thanks. I appreciate your help.

    • This reply was modified 1 year, 6 months ago by donsign.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Play a sound when clicking on a marker’ is closed to new replies.