How to termiinate webviewer audio?

I have the following blocks implemented. Can not get it to work as planned.

Each section called on the same page by the viewer is an audio file. The button clicks to randomly select a different section. It is all fine, if the audio play is stopped before the button clicks.

While the audio is being played, and the user click the button, the webviewer switches to another section, the visual changes, but the audio from previous section still plays in the background. What can you advise. Thank you.

Screenshot (25)

This is online or offline html file

Online fetch from a website. I wrote some jQuery so that only one section can be displayed at one time.

Add this line off code in website. This event is called whenever tab is unfocussed if you change page then i think this works
window.onblur = function (){ const audio = document.getElementById('audio'); audio.stop() }
Where audio is id of element you may have different

Thanks, where do I insert it. In the header of the page or the website???

Basically script will be add in below of body for fast loading website.

If possible add in websites so its work for all pages

Thank you ShaikhSajidAli.

I inserted the javascript at the end of the page. Unfortunately, it did not stop the audio, when I executed the blocks in the uploaded diagram.

Any modification of the script you can think of?

Did you inserted as it is or change you need to change id of whatever you have in audio tag in html

ShaikhSajidAli, Thank you for your support. I see that you were trying to use some audio tag to stop it. I don’t know about audio tag. I was using hastag in the Url to identify each audio section as follows:

jQuery( document ).ready( function () {

if(window.location.hash) {
	var hashtag = location.href.substring(location.href.indexOf("#")+1);
	var divtoShow = jQuery("#" + hashtag);	
	var hashtagstring= hashtag.substr(0, hashtag.indexOf('-')); 
	
	
	if ( divtoShow.length > 0 ) {
		for (i = 1; i < 500; i++) {
			if ( hashtag == hashtagstring + "-" + i ) {
				divtoShow.show();
			} else {
				jQuery("#" + hashtagstring + "-" + i).hide();
			}
		}
	}
}

function hashHandler() {
	if(window.location.hash) {
		var hashtag = location.href.substring(location.href.indexOf("#")+1);
		var divtoShow = jQuery("#" + hashtag);	
		var hashtagstring= hashtag.substr(0, hashtag.indexOf('-'));		
		if ( divtoShow.length > 0 ) {
			for (i = 1; i < 500; i++) {
				if ( hashtag == hashtagstring + "-" + i ) {
					divtoShow.show();
				} else {
					jQuery("#" + hashtagstring + "-" + i).hide();
				}
			}
		}
	}
}

window.addEventListener('hashchange', hashHandler, false);

window.addEventListener('locationchange', function(){
	hashHandler();
});

});

I entered
jQuery("#" + hashtagstring + “-” + i).stop(true);
under the
jQuery("#" + hashtagstring + “-” + i).hide();
But it does not work.

Any advise?

Thank you as always.

This code is not related to audio this is just showing and hiding div in dom

You may have to set the go to url “empty” before calling or loading another url. Because it looks like webviwer urls are not switching correctly

Thank you, Tejaskhopkar2,

You are correct. I find a solution as follows: Instead of using button click, I used touchdown to goto url, then use touchup to reload the page.

This is the only way to terminate the previous audio. Because stop() does not stop it.

Thank all of you for helping out.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.