0

Javascript sound not playing

<html> <head> <title> </title> </head> <body background="C:\Users\deadl\Desktop\Website\phuket6.jpg"> <body> <script> var audio, playbtn;seek_bar; function initAudioPlayer(){ audio= new Audio (); audio.src ="C:\Users\deadl\Desktop\Website\Beach-ambience\Beach-ambience.mp3"; audio.play(); } window.addEventListener("load",initAudioPlayer); </script> <center><h1>Welcome to Phuket</h1></center> <p><b> <font size="5" font color="black"><div align="left">Phuket is one of the finest beach destinations in Thailand with fine white sands, nodding palm trees, glittering seas and lively towns. It has plenty of hotels to choose from. you can take an exhilarating speedboat trip to the many nearby tropical paradises, including the famous Phi Phi Islands, or enjoy a cruise around the mystical Phang Nga Bay. Phuket is blessed with more than 30 amazing beaches to choose from. Patong Beach, Kata, Karon and Kamala have always been the most popular, but the north of the island reveals some hidden gems for travellers searching for a more romantic atmosphere</align></b></font></p> <p> <a href="Homepage.html"> <center><font color="blue" font size="25">Back To Map</font></center> <a/> </p> </html> Can someone help ? I have no clue how Javascript works. The browser isn't playing my sound file at all Thanks Harry

6th Nov 2018, 11:48 PM
harry
2 Respostas
+ 4
audio events can only be triggered by a user action. you cannot trigger audio events programmatically,a user has to click stuff,or perform an action for an audio to be played also next time,try inserting your code into the JavaScript playground and post a link,inserting your code directly in your post makes it difficult to read
7th Nov 2018, 12:11 AM
᠌᠌Code X
᠌᠌Code X - avatar
0
Okay got it. Do you know how I can go about creating a play button and upon user clicking it; it plays the sound file on my browser ?
7th Nov 2018, 1:14 AM
harry