I have an HTML site with which music starts on entering, but I want it to stop when the user clicks play on the youtube video that is embedded onto my website.. so it makes the background music and the video music not be able to run simultaneously because that's annoying.
Any idea on how to do that? or if there is any solution for this problem?
Detect the player's state change (
onStateChange
event) using JavaScript: https://developers.google.com/youtube/js_api_reference#EventsIf the video is loaded using an
iframe
(as the comments indicate) see Guide for YouTubeiframe
embeds (note the code sample which detects player events).Example
When the player starts, use JavaScript to stop the audio. You haven't told us how it is embedded into the page, but nearly any player can be stopped with script (even
bgsound
can be hacked).And encourage your client to not auto-play music when the page loads. From a pure business standpoint, it can cost you customers.