Home > OS >  Please explain why my mp3 file won't play
Please explain why my mp3 file won't play

Time:03-21

I'm watching a Youtube video to learn HTML and CSS.

https://www.youtube.com/watch?v=cyuzt1Dp8X8&t=5566s

I downloaded an mp3 file to my computer, but when I run my code, the audio file doesn't play. In my HTML code, I used the name of the audio file rather than the path. I know the name of the mp3 file is correct. However, by using the path rather than the file name, I have been able to play the audio in my browser. Again, the first code will NOT play the audio file, but the second code will play the audio file.

<audio controls>
<source src="CouldItBeKP.mp3" />
</audio>

<audio controls>
<source src="C:\Users\james\Downloads\CouldItBeKP.mp3" />
</audio>

Also, the author of the Youtube video believes the location of the audio file matters. For example, the audio file won't play if I move the mp3 file from Desktop to Downloads or vice versa. The code is below.

<audio controls>
<source src="CouldItBeKP.mp3" />
</audio>

Please help! Thanks.

CodePudding user response:

When you do not specify the full path, most browsers will assume that the file is in the same folder. So if your code was in ~\Documents, but the audio was in ~\Downloads, it would not play. If they were both in ~\Documents, it would play.

CodePudding user response:

You need the path to be correct, without the path it greys out. Put it in your main directory and try ./CouldItBeKP.mp3

CodePudding user response:

it seems like your audio files are on the downloads folder, but I'm not sure where your code is. What I would suggest is, you move your audio files and your codes to the same directory. Then your second code will also play the audio.

  • Related