I am currently working on a SharePoint page and trying to put an audio file on my page but it doesn't even display in IE8. It worked fine at the beginning but it is not even displaying now. Just to clarify it works perfectly in Chrome. Do you guys know any alternative that works?
var audio = document.getElementById('mytrack');
setTimeout(function() {
audio.play();
}, 4000);
audio#mytrack {
width:330px;
height:40px;
}
<div id="wrapper">
<audio id="mytrack" controls>
<source src="../downloads/wpw.mp3" type="audio/mp3">
<source src="../downloads/wpw.ogg" type="audio/ogg">
<source src="../downloads/wpwv.wav" type="audio/wav">
</audio>
</div>
You can use audio.js to solve this problem. Not sure if you wanted to use a plugin or not but this does work with IE8. I hope this helps!
Related
And if it stops it won't autoplay on reload or opening the site like it should. Once it has stoped it won't even work when i restart the localhost server again. I uploaded my files to github to test if it is something with my local server. So the problem still appears and i have no clue how to solve it since autoplay is active. If someone could help out i would appreciate that. Thanks in advance !
I changed autoplay and loop in the index file to autostart="true" didn't work either so i sticked to autoplay loop. i added buttons to stop the audio if anybody wants to.
<audio id="background-audio" class="background-audio" autoplay loop >
<source class="background-audio" type="audio/mpeg" src="audio/videoplayback7.m4a">
</audio>
var audio = document.getElementById("background-audio")
function belltwo() {
audio.play();
}
function bellthree() {
audio.pause();
}
website link : https://depressedunicorn.github.io/NiRiN/ if you want to test out the problem yourself
yeah already found the solution ^^ but only works on localhost server now: i can now stop the audio restart the page and it will autoplay everytime. but not on github page maybe it takes time for the changes to take effect.
<audio id="background-audio" class="background-audio" autoplay="autoplay" loop="loop">
<source type="audio/mpeg" src="audio/videoplayback7.m4a">
</audio>
<video id="background-video" class="background-video" allowfullscreen="true" muted="true" autoplay="autoplay" playsinline="playsinline" loop="loop">
<source src="/img/beepleloops/beepleDnB93.mp4" type="video/mp4">
while I am trying to autoplay a song in chrome but it is not working. I tried using JavaScript still getting the same error.
function myFunction() {
var x = document.getElementById("myAudio").autoplay;
document.getElementById("demo").innerHTML = x;
}
myFunction();
<audio id="myAudio" controls autoplay>
<source src="https://www.w3schools.com/tags/horse.mp3" type="audio/mp3">
Your browser does not support the audio element.
</audio>
<div id="demo"></div>
In most browsers you can only use autoplay with the muted attribute
See: https://www.w3schools.com/tags/att_audio_autoplay.asp
Note: Chromium browsers do not allow autoplay in most cases. However, muted autoplay is always allowed.
So something like this should work:
<audio id="myAudio" controls autoplay muted>
<source src="horse.mp3" type="audio/mp3">
Your browser does not support the audio element.
</audio>
It is not allowed to autoplay sounds. So it has to be muted. Also with video you have to mute it, otherwise the video is not played. So it will be with audio also. Maybe you have to add a button that says that they have to click it to hear the sound?
I have a javascript code like below:
<script type="text/javascript" charset="utf-8">
function addmsg(count, play){
if(play == 'true')
{
$("#my_audio").get(0).play();
}
}
</script>
<html>
<audio id="my_audio" src="popsound.mp3"></audio>
</html>
In the above code "play" variable is like a flag containing true or false value, and it plays the sound when play=='true'.The above code is working fine on my laptop browser,but when I'm accessing the page through my mobile the sound doesnt gets played. I did some research but I'm unable to figure out how to do it in my case. I'm very new to this field so sorry if this question is senseless, but can any one please help me. I wanted to make it work fine for mobile browser's too.Thank you in advance.
You need to put different formats for all devices (.ogg and .mp3).
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Source : http://www.w3schools.com/html/html5_audio.asp
Before I ask my question I just wanted to say that I'm a noob to Javascript and to StackOverflow in general so I wanted to apologize in advance if this question is too dumb.
Anyways, I'm learning Javascript and right now I'm experimenting with currentTime, but for some reason song.currentTime is returning undefined, and I also can't set the currentTime. Here is my code:
<audio autoplay>
<source src="A.mp3" type="audio/mpeg" id="awesomeness">
Your browser does not support the audio element.
</audio>
<script type="text/javascript">
function myFunction(){
console.log("letting everything preload by waiting 2 seconds");
var song= document.getElementById("awesomeness");
console.log(song.currentTime);
song.currentTime=30;
}
</script>
Here it is in action (look at the console output): http://dancingcats.azurewebsites.net/
The currentTime property belongs to the audio element(Media)
You need is to set it to the audio element not to the source element
<audio autoplay id="awesomeness">
<source src="A.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
I'm still not really 'good' with Javascript and jQuery but I'm learning. The following, however, puzzles me:
I have a standard HTML5 video tag:
<video id="videoclip">
<source src="video.mp4" type="video/mp4">
<source src="video.webm" type="video/webm">
</video>
Now I need to change to video src via jQuery. If I only have ONE source i.e.
<source id="mp4" src="video.mp4" type="video/mp4">
I just do THIS:
function changeVideo() {
var newVideo = "new_video.mp4";
$("#videoclip").attr("src",newVideo) }
(I abbreviated this snippet. I actually have quite a few variables and things that happen set up there).
So this works well. But what do I need to do if I have TWO sources as in the very first code segment? An alternative webm file?
I tried giving the two source tags different IDs like so:
<source id="mp4" src="video.mp4" type="video/mp4">
<source id="webm" src="video.webm" type="video/webm">
and then did this:
function changeVideo() {
var newVideo = "new_video.mp4";
var newVideo2 = "new_video.webm";
$("#mp4").attr("src",newVideo);
$("#webm").attr("src",newVideo2)
Doesn't work. I mean it DOES the first time I play the video but when I use another similar function to change the sources yet again it won't work. It will be the same source set in the first place. It won't budge. :(
Everything I wrote over the last hours works perfectly now with this exception.
How do I get past this exception?
You need to add this in the changeVideo function:
$("#videoclip")[0].load();
$("#videoclip")[0].play();