Simple Background Music for website - html

I have been designing a website recently and I had the idea to try implementing some background music.
I went about this by simply having the music play through a video looper
<embed name="Example Song Here"
src="http://www.infinitelooper.com/?v=GGtcJCzB9cU&p=n"
loop="True"
hidden="true"
autostart="true">
</embed
That works perfectly, the problem comes that users will probably want to stop the music, so I added a "Stop Music" button
FORM METHOD="LINK" ACTION="WebsiteURL">
<INPUT TYPE="submit" VALUE="Stop Music">
</FORM>
Adds the button fine, but as you can see it doesn't do anything but redirect back to the site, I've been looking for that extra line I need to make the button stop the music above.
Yes, I'm a total novice.

This code uses Html5. if you can use html5 this works fine.
<audio id="myAudio"
<source src="http://media.w3.org/2010/07/bunny/04-Death_Becomes_Fur.mp4"
type='audio/mp4'>
<source src="http://media.w3.org/2010/07/bunny/04-Death_Becomes_Fur.oga"
type='audio/ogg; codecs=vorbis'>
Your user agent does not support the HTML5 Audio element.
</audio>
<button type="button" onclick="aud_play_pause()">Play/Pause</button>
<script>
function aud_play_pause() {
var myAudio = document.getElementById("myAudio");
if (myAudio.paused) {
myAudio.play();
} else {
myAudio.pause();
}
}
</script>

The embed element as such is conforming in the current HTML specification (HTML5), but it isn’t what it used to be. The old, nonstandard embed element had various attributes that controlled the presentation, but they are not included in the specification and support to them varies greatly and is diminishing. Besides, your example does not actually embed sound directly. Instead, it embeds an HTML element, which has embedded sound its own way. Normally you cannot control what happens on a page that you embed from another server.
There is no HTML way to control playing in an embed element, since it is expected to be implemented with a plugin. Note that modern browsers might lack any plugins for the purpose by default or might have such plugins disabled. So embed really isn’t what it used to be.
Others have suggested, for good reasons, that you don’t use background sound and that if you use, implement it with the audio element. (You could have an embed element inside the audio element, as fallback content for browsers that do not recognize audio markup at all.) However, audio only applies to direct embedding of sound, as opposite to embedding a page that has background sound.
In your case, you can create your own stop button using JavaScript. You can make a click on the button to simply remove the embed element. Of course, it would then simply terminate the sound. Removing an element is a bit indirect in JavaScript: you tell its parent to kick that child out.
<embed id=bgs name="Example Song Here" controls=stopbutton
src="http://www.infinitelooper.com/?v=GGtcJCzB9cU&p=n">
</embed>
<button onclick=
"var bgs = document.getElementById('bgs'); bgs.parentNode.removeChild(bgs);
this.parentNode.removeChild(this)">
Stop background sound</button>

Related

How does html5 video tag works? Is there any way to see how it is implemented

I am developing an application where I need to display some animation in the canvas along with the video as a separate element, for the same I need to maintain the synchronisation between two DOM elements very precisely.
I was thinking of playing the animation as video tag plays the video. Is there any way I could see how the html5 video tag is implemented?
Theoretically, each browser can have their own implementation of the video tag. Besides of that, they will try their best to follow some rules specified by w3.org
This is the video tag draft:
https://www.w3.org/TR/2011/WD-html5-20110113/video.html#video
If yout want to sync something with a video you will want to use some video tag events:
https://www.w3.org/2010/05/video/mediaevents.html
A timeupdate event listener can be set on the video which will allow you to synchronize other elements on the page with the video as it plays. Video elements have many other events in addition to timeupdate, such as play, pause, and seeking.
The implementation of video elements will differ depending on the browser and may not be completely public, such as how they work with DRM.

TinyMCE Stripping Out "controlsList" Attribute on HTML 5 Audio Tag

In the TinyMCE editor I want to add a valid element attribute, the HTML5 audio and video attribute "controlList". It's an experimental attribute but supported in Chrome and we have a use for it. For example we want the following code to validate in TinyMCE:
<p>
<audio controls="controls" controlsList="nodownload">
<source src="some.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
</p>
Right now 'controlsList="nodownload"' is not recognized and stripped out.
Tiny MCE's documentation shows that adding custom tags and attributes is possible using tinyMCE.init (https://www.tiny.cloud/docs/configure/content-filtering/#valid_elements). However I've looked at the source of 2sxc and I am not quite clear about the best way to do this in 2sxc's implementation of TinyMCE.
One possibility seems to be line 2045 of the file \dist\sxc-edit\sxc-edit.js (2sxc 9.14). There I added the tags & attribute to the existing validateAlso:
validateAlso: '#[class]' // allow classes on all elements,
+ ',i' // allow i elements (allows icon-font tags like <i class="fa fa-...">)
+ ",hr[sxc|guid]" // experimental: allow inline content-blocks
+ ",audio[controlsList]"
+ ",video[controlsList]"
However that didn't have the desired effect on my testing server and I don't love the idea of modifying source since my changes will be overwritten by the next patch I apply.
What is the right way to do this?
Here is a work around that allows custom attributes to be added to an HTML tag. Note this solution works for our one-off needs with HTML5 audio/video tags but may not work for everyone.
First we added an id of "my-player" to our audio tag.
<audio id="my-player" controls="controls">
<source src="some.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Then we added a script which inserts the desired attribute using DNN Page Settings > Advanced > SEO > Page Header Tags:
<script>
$( document ).ready(function() {
$('#my-player').attr("controlsList", "nodownload");
});
</script>
In our case this javascript attribute insertion had the desired effect.
As of now, tinyMCE is not configurable. Reason is that we're moving to a completely new implementation of the UI using Angular 7, and we don't want to introduce more features to migrate :)
If you really want to do this, I recommend you use the code for the input-type "string-wysiwyg" to create your own - let's call it "string-wysiswyg-withfeatures" and register it as an input-type (there are some blogs about that) - then configure your field to use that wysiwyg.

Is it possible to add alt attribute for the poster of the video?

Can I add an alt info for the image used as the poster in HTML5?
<video controls poster="/images/w3html5.gif">
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
Just because it is an image does not imply that it will behave like an <img> tag. In fact in this case it is not even a tag, and there would be no way to do that.
Nesting <img> inside <video> would not have the desired effect, since the browser will interpret it only if it doesn't know about <video> tag at all (i.e. an old browser), and this is not the demographic you are shooting for.
What are you attempting to do here?
If you are adding alt to achieve some sort of search engine optimisation, then you should only do so in the event that search engine will actually recognise it as legitimate text to index and identify with the image in question. In this case it may very well be a good idea to add an <img> inside your <video> as so:
<video poster='image.png'>
<source .../>
<img src='image.png' alt='Image showing a cute cat' />
Unfortunately your browser is too old.
</video>
If, on the other hand, you are attempting to do this to enable screen-reader to understand what is displayed there; then you are in much more trouble, since they are usually smarter than most search engines, and will often read text under the cursor. The approach above will not work, since <img> will not be displayed at all. I don't know enough about screen readers to help you further.
We had the same question for Coverr.co's videos - although they are sound-less, we wanted a way to describe the videos for visually impaired users or users who are using old browsers (which do not support html 5 <video> tag).
A nice additional benefit for making videos accessible is that you're getting extra SEO boost, since google can't crawl videos, but can definitely crawl the additional accessible text we're adding to our HTML.
Bottom line/TLDR - although alt attributes have been around and are widely used for images, it seems there isn't an equivalent native attribute for videos. The reasoning for that is here, if you're interested, but I feel it's not strong enough to miss out on all the benefits of having a simple tag for people who wouldn't be able to watch the video at all otherwise.
What we DO have?
Transcript - a description of "what is happening in the video". There is no native support for that, but there are some recommendation on how to integrate it into the html. One suggestion which seems simple and effective (taken from here):
function showTranscript() {
var x = document.getElementById('transcript');
// var toggle = document.getElementById('trans_toggle');
if (x.style.display === "none" || !x.style.display) {
x.style.display = "block";
this.text = "hide transcript"
} else {
x.style.display = "none";
this.text = "see transcript"
}
}
document.addEventListener("DOMContentLoaded", function(event) {
var toggle = document.getElementById('trans_toggle');
toggle.onclick = function() {
showTranscript();
};
});
#transcript {
display: none;
}
<h2 id="title">Title of my video</h2> (see transcript)
<video src="foo.ogv" aria-labelledby="title" aria-describedby="transcript">
<track kind="captions" label="English captions" src="captions.vtt" srclang="en" default></track>
</video>
<div id="transcript">
<strong>Transcript of the video:</strong> Transcript here
</div>
another option is using the aria attributes, and while valid and even recommended, this approach is not supported as much.
Captions - if I understand correctly, the right way to integrate it is by using the <track> tag. What are captions? as taken from the Media accessibility checklist:
Captions should not be confused with subtitles — they are similar, yet distinct from each other. While subtitles are a straightforward translation of the video’s dialogue, often times in a different language, captions not only have a text description of the spoken word but also include description of the background music or sound so as to provide the same level of information as one would get from hearing the audio.
Subtitles - straightforward translation of the video’s dialogue. We don't need it in Coverr since all of our stock videos are without sound, but this is of course a very effective way to allow hearing impaired users (and 85% of the users on FB which never unmute the videos as they scroll their feed) to "listen in" to your videos. Can be embedded in the video itself, or added as VTT file and shown by supported players.
Fallback text (not for accessibility, but will help users who are using old browsers).
Useful links:
Thoughts/plans for adding native transcript tag to the HTML standard.
Adding captions and subtitles to HTML videos.
Captions on the web and FCC compliance + converting to VTT.
I'm aware this is not your common, definitive SO answer, but the current state of video accessibility on the web needs all the support it can get.
Would love any comments or improvement suggestions, as this is for us, still, an unsolved issue natively which should evolve to a standard solution ASAP.

Embedding a media player in a website using HTML [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
What I want to do is to embed music files within a website (Have something a'la little mp3 player on the site). I want the audience to be able to play, stop etc the songs by using custom made controllers.
How do I code those custom made buttons so that they all work fine?
You can use plenty of things.
If you're a standards junkie, you can use the HTML5 <audio> tag:
Here is the official W3C specification for the audio tag.
Usage:
<audio controls>
<source src="http://media.w3.org/2010/07/bunny/04-Death_Becomes_Fur.mp4"
type='audio/mp4'>
<!-- The next two lines are only executed if the browser doesn't support MP4 files -->
<source src="http://media.w3.org/2010/07/bunny/04-Death_Becomes_Fur.oga"
type='audio/ogg; codecs=vorbis'>
<!-- The next line will only be executed if the browser doesn't support the <audio> tag-->
<p>Your user agent does not support the HTML5 Audio element.</p>
</audio>
jsFiddle here.
Or, if you want to support older browsers, you can use many of the free audio flash players available. Such as:
Dewplayer
MP3 Player (boring name... right? :) )
Website Music Player (even more boring... right?)
Zanorg Player
Note: I'm not sure which are the best ones, as I have never used one (yet).
UPDATE: As mentioned in another answer's comment, you are using XHTML 1.0 Transitional. You might be able to get <audio> to work with some hack.
UPDATE 2: I just remembered another way to do play audio. This will work in XHTML!!! This is fully standards-compliant.
You use this JavaScript:
var aud = document.createElement("iframe");
aud.setAttribute('src', "http://yoursite.com/youraudio.mp4"); // replace with actual file path
aud.setAttribute('width', '1px');
aud.setAttribute('height', '1px');
aud.setAttribute('scrolling', 'no');
aud.style.border = "0px";
document.body.appendChild(aud);
This is my answer to another question.
UPDATE 3: To customise the controls, you can use something like this.
Definitely the HTML5 element is the way to go. There's at least basic support for it in the most recent versions of almost all browsers:
http://caniuse.com/#feat=audio
And it allows to specify what to do when the element is not supported by the browser. For example you could add a link to a file by doing:
<audio controls src="intro.mp3">
Introduction to HTML5 (10:12) - MP3 - 3.2MB
</audio>
You can find this examples and more information about the audio element in the following link:
http://hacks.mozilla.org/2012/04/enhanceyourhtml5appwithaudio/
Finally, the good news are that mozilla's April's dev Derby is about this element so that's probably going to provide loads of great examples of how to make the most out of this element:
http://hacks.mozilla.org/2012/04/april-dev-derby-show-us-what-you-can-do-with-html5-audio/
Here is a solution to make an accessible audio player with valid xHTML and non-intrusive javascript thanks to W3C Web Audio API :
What to do :
If the browser is able to read, then we display controls
If the browser is not able to read, we just render a link to the file
First of all, we check if the browser implements Web Audio API:
if (typeof Audio === 'undefined') {
// abort
}
Then we instanciate an Audio object:
var player = new Audio('mysong.ogg');
Then we can check if the browser is able to decode this type of file :
if(!player.canPlayType('audio/ogg')) {
// abort
}
Or even if it can play the codec :
if(!player.canPlayType('audio/ogg; codecs="vorbis"')) {
// abort
}
Then we can use player.play(), player.pause();
I have done a tiny JQuery plugin that I called nanodio to test this.
You can check how it works on my demo page (sorry, but text is in french :p )
Just click on a link to play, and click again to pause. If the browser can read it natively, it will. If it can't, it should download the file.
This is just a little example, but you can improve it to use any element of your page as a control button or generate ones on the fly with javascript... Whatever you want.
I found the that either IE or Chrome choked on most of these, or they required external libraries. I just wanted to play an MP3, and I found the page http://www.w3schools.com/html/html_sounds.asp very helpful.
<audio controls>
<source src="horse.mp3" type="audio/mpeg">
<embed height="50" width="100" src="horse.mp3">
</audio>
Worked for me in the browsers I tried, but I didn't have some of the old ones around at this time.
<html>
<head>
<H1>
Automatically play music files on your website when a page loads
</H1>
</head>
<body>
<embed src="YourMusic.mp3" autostart="true" loop="true" width="2" height="0">
</embed>
</body>
</html>
If you are using HTML 5, there is the <audio> element.
On MDN:
The audio element is used to embed sound content in an HTML or XHTML document. The audio element was added as part of HTML5.
Update:
In order to play audio in the browser in HTML versions before 5 (including XHTML), you need to use one of the many flash audio players.

How do you play a sound on the web browser?

How do I play a sound on the web browser as notification?
You can use the <audio> tag combined with JavaScript to play sounds at a given time. You'll need JavaScript, of course, as it's done on the frontend, and hence, with client-side programming.
For example,
<audio style="display: none;" id="notification" preload src="path/to/soundfile">
Then, for the scripting, place this somewhere in any part of your script that requires sound notification to occur:
document.getElementById('notification').play();
For those who recommend Flash as it's supported in IE, note graceful degradation, where, for non-essential things (such as sound notification) we choose to use new, recommended technologies that work on most browsers, instead of using hackish, insecure methods to try to get all browsers to work.
With HTML5 you can use a bit of javascript and the <audio>-tag.
I have an example on my site: http://www.khaaaaan.com
The javascript:
<script type="text/javascript">
function soundPlay(which)
{
var audio = document.getElementById(which);
audio.play();
}
</script>
The button which activates the sound:
<input type="button" class="khaaaaan" onclick="soundPlay('khaaaaan');" Text="KHAAAAAN!" title="CLICK MEEEEEEEEE!" />
And then the audio-tag
<audio src="khaaaaan.wav" autobuffer="autobuffer" id="khaaaaan" />
This also works (Used it before the <audio>-script :)
Cross-platform, cross-browser way to play sound from Javascript?
Since the audio tag isn't normative, I'd suggest using the 'legacy' way of handling this.
Here's another SO post that deals with it:
Cross-platform, cross-browser way to play sound from Javascript?
You could also embed a Flash widget which could perform all sorts of other useful things at the same time, including keeping track of how many times a user has triggered a sound prompt, or provide an interface for disabling such aural prompting. Using Flash would also offer you streaming functionalities and flash cookie local data storage.
Though you can do it with audio tag it wont work in browsers that don't support HTML5. The easiest way to do will be using...
<embed src="1.mp3" width="200" height="55" autostart="true" loop="true" style="visibility:none; position:fixed;">
This uses the default player. Eg: Media Player in windows.
But the standard way is using flash
An tutorial can be found here.
This also works in all web browsers IE4 +, Firefox(all), Chrome... And don't depend on HTML 5 or Flash, and uses the default player which is always there.
N.B:
EMBED tag is not a part of the HTML 4 or xHTML 1 specifications, but it is still widely supported by modern browsers. Unlike other tags, the attributes used by EMBED tag depend on the type of plugin being used (this odd free-attribute concept is why EMBED tag has been rejected by the HTML standards makers).
But this solves problems :)