Play sound file in a web-page in the background - html

I want to play a sound file on my web-page in the back-ground(don't want Media player UI to appear), my web-site will run on Fire-Fox, i used the Embed element and set the Hidden attribute to be true <embed name="myMusic" src="Masgon.mp3" type="audio/midi"
autostart="false" Hidden="true" loop="true"></embed>
the problem is that no sound is played unless i removed the hidden attribute on this case the sound file is played and the media player UI appears but i don't want that.

<audio src="/music/good_enough.mp3">
<p>If you are reading this, it is because your browser does not support the audio element. </p>
</audio>
and if you want the controls
<audio src="/music/good_enough.mp3" controls>
<p>If you are reading this, it is because your browser does not support the audio element.</p>
</audio>
and also using embed
<embed src="/music/good_enough.mp3" width="180" height="90" loop="false" autostart="false" hidden="true" />

<audio src="/music/good_enough.mp3" autoplay>
<p>If you are reading this, it is because your browser does not support the audio element. </p>
<embed src="/music/good_enough.mp3" width="180" height="90" hidden="true" />
</audio>
Works for me just fine.

Though this might be too late to comment but here's the working code for problems such as yours.
<div id="player">
<audio autoplay hidden>
<source src="link/to/file/file.mp3" type="audio/mpeg">
If you're reading this, audio isn't supported.
</audio>
</div>

<audio controls autoplay loop>
<source src="path/your_song.mp3" type="audio/ogg">
<embed src="path/your_song.mp3" autostart="true" loop="true" hidden="true">
</audio>
[ps. replace the "path/your_song.mp3" with the folder and the song title eg. "music/samplemusic.mp3" or "media/bgmusic.mp3" etc.

With me the problem was solved by removing the type attribute:
<embed name="myMusic" loop="true" hidden="true" src="Music.mp3"></embed>
Cerntainly not the cleanest way.
If you're using HTML5:
MP3 isn't supported by Firefox. Wav and Ogg are though.
Here you can find an overview of which browser support which type of audio:
http://www.w3schools.com/html/html5_audio.asp

If you don't want to show controls then try this code
<audio autoplay>
<source src="song.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>

if you want it just normal:
<audio src="sus.mp3">
<script>alert("Your browser doesn't support the Audio tag!")</script>
</audio>`
if you want it to automatically start on load: (Not supported by chrome)
<audio src="sus.mp3" autostart="true">
<script>alert("Your browser doesn't support the Audio tag!")</script>
</audio>
if you want the controls
<audio src="sus.mp3" autostart="true" controls>
<script>alert("Your browser doesn't support the Audio tag!")</script>
</audio>

Related

HTML Audio component controls not showing download in Safari

I have an audio component declared in React with controls like this:
<audio controls>
<source src={url} />
</audio>
This is working in all the browsers except Safari. When I try to use the audio controls it only appears the speed of the audio (0.5x, 1x, 1.25x, etc...) but there is no download option.
What am I missing?
try adding more Media container formats on order to support more platforms and browsers :
<audio controls>
<source src={url} type="audio/mpeg" />
<source src={url} type="audio/ogg" />
</audio>

Mp3 file uploaded to Ghpages won't play. I have tried using rawgit to host the file and githubusercontent and it still won't work?

This is the local code that I have and it works.
<audio preload="auto" autoplay="autoplay">
<source src="halloween_theme.mp3" type="audio/mp3" />
</audio>
This was what I read to do from another stackoverflow
<audio preload="auto" autoplay="autoplay">
<source src="https://raw.githubusercontent.com/jerryhoglen/halloween_site/master/halloween_theme.mp3" type="audio/mp3" />
</audio>
I have tried hosting the track on google drive and it won't work there either.
I found the answer. Chrome has updated and removed the autoplay feature but there is a workaround using iframes to play mp3 audio.
<iframe src="audio/halloween_theme.mp3" allow="autoplay" style="display:none" id="iframeAudio"></iframe>

How can I add control to my embed audio?

I added some music to my website that starts when you load it. I also want to give the option to pause/unpause it. What must I do to add control?
<embed controls autostart="true" height="0" loop="true" src="URL://music-file" width="0" />
Use HTML5
A simple way to achieve this is, to use HTML5 and it's audio tag.
<audio controls autoplay>
<source src="MP3 PATH" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

How to open .mov format video in HTML video Tag?

I want to play .mov video like as this, but video doesn't play in any browser.
<video width="400" controls Autoplay=autoplay>
<source src="D:/mov1.mov" type="video/mov">
</video>
You can use below code:
<video width="400" controls autoplay>
<source src="D:/mov1.mov" type="video/mp4">
</video>
this code will help you.
Instead of using <source> tag, use <src> attribute of <video> as below and you will see the action.
<video width="320" height="240" src="mov1.mov"></video>
or
you can give multiple tags within the tag, each with a different video source. The browser will automatically go through the list and pick the first one it’s able to play. For example:
<video id="sampleMovie" width="640" height="360" preload controls>
<source src="HTML5Sample_H264.mov" />
<source src="HTML5Sample_Ogg.ogv" />
<source src="HTML5Sample_WebM.webm" />
</video>
If you test that code in Chrome, you’ll get the H.264 video. Run it in Firefox, though, and you’ll see the Ogg video in the same place.
Unfortunately .mov files are not supported with html5 video playback. You can see what filetypes are supported here:
https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats
If you need to be able to play these formats with your html5 video player, you'll need to first convert your videofile--perhaps with something like this:
https://www.npmjs.com/package/html5-media-converter
Content Type for MOV videos are video/quicktime in my case. Adding type="video/mp4" to MOV video file solved issue in my case.
<video width="400" controls Autoplay=autoplay>
<source src="D:/mov1.mov" type="video/mp4">
</video>
in the video source change the type to "video/quicktime"
<video width="400" controls Autoplay=autoplay>
<source src="D:/mov1.mov" type="video/quicktime">
</video>
You can use Controls attribute
<video id="sampleMovie" src="HTML5Sample.mov" controls></video>
My new answer is to use ffmpeg to transcode the .mov like ffmpeg -i sourceFile.mov destinationFile.mp4. Do same for the webm format.
OLD Answer:
Here's what you do:
Upload your video to Youtube.
Install the "Complete YouTube Saver" plugin for Firefox
Using the plugin in Firefox, download both the MP4 and WEBM formats and place them on your Web server
Add the HTML5 Video element to your webpage per MDN's recommendation
<video controls>
<source src="somevideo.webm" type="video/webm">
<source src="somevideo.mp4" type="video/mp4">
I'm sorry; your browser doesn't support HTML5 video in WebM with VP8/VP9 or MP4 with H.264.
<!-- You can embed a Flash player here, to play your mp4 video in older browsers -->
</video>
Style the <video> element with CSS to suit your needs. For example Materializecss has a simple helper class to render the video nicely across device types.

Why isn't my audio element working in HTML5?

I am using the chrome 37 and firefox 31.
When I add the audio tag for chrome. It just doesn't play. There is a cross over the sound control icon
On firefox v31 it just disappears. When I check th w3schools website it works fine. I am using exactly the same code they are using with and doubled check the audio src to make sure its correct but it still doesn't play. Can anyone please help me figure out whats going on??
Below is my code
<audio controls>
<source src="new_simplemenu_order.mp3" type="audio/mpeg" >
Your browser does not support the audio element.
</audio>
I was having the same problem.
It seems to work by if you change your file type to .ogg and also don't use underscores in your file name.
Also, try altering your code to this (credit to superuser.com):
<audio controls preload="auto">
<source src="NewSimpleMenuOrder.ogg" type="audio/ogg" />
</audio>
You can hide the controls by doing the following
<audio preload="auto">
<source src="NewSimpleMenuOrder.ogg" type="audio/ogg" />
</audio>
And autoplay by doing this:
<audio autoplay>
<source src="NewSimpleMenuOrder.ogg" type="audio/ogg" />
</audio>
(I hope this fixes your problem!)