I needed a "ding" sound effect for a pomodoro app that I am building, and I found this sound which met my requirements. I play the sound in my application like this:
var audio = new Audio('ding.wav');
audio.play();
My problem is that, while the sound does play, after the sound finishes playing I hear loud, high pitched digital feedback for about a second.
I have not had this issue before when working with mp3s, so to ensure that it was not related to the file type, I tried using a different .wav file from the same website. This file, when played in the same way is not followed by the feedback. Also, the timing suggests that ding.wav has finished playing completely before the feedback starts.
The file that is followed by the feedback does not have any feedback when played through the media player on my computer.
What would cause this kind of audio feedback, and how can I fix it? I have searched on here and looked through the documentation for HTMLAudioElement, but haven't found anything useful so far. I tried lowering the .volume of the element to see if it was related to that, but it didn't make a difference.
If it would be helpful to actually hear what I am hearing, I can make a video and link to it, but I am not sure how else to give an example in e.g., a fiddle, because the audio file is stored locally on my computer.
Update:
I am not sure if this makes the problem clearer, but the issue does appear to be tied to the playing of the sound rather than the audio file itself. Currently, for testing purposes, the playing of the sound is tied to the pressing of a button. If I quickly press the button 5 times in a row the full sound effect will only play fully once (i.e., if I press the button before the sound is finished, the sound is cut off and starts again), but after the sound fades out from the last button press, I will hear one loud feedback beep for each time I pressed the button (i.e., five beeps for five button presses etc.).
Related
I want to generate a "beep" sound every minute on the web browser.
For the "every minute" thing I rely on setInterval() since there is a seconds counter and I want to update the second counter every second. I am well aware of the non-real timing facts going on but it's not a big deal in this case.
The real deal is generating a short notification sound after every 59 seconds.
I am currently doing it using the audio API.
As follows:
a=new AudioContext();
function pitar(volumen, frecuencia, duracion){
v=a.createOscillator()
u=a.createGain()
v.connect(u)
v.frequency.value=frecuencia
v.type="square"
u.connect(a.destination)
u.gain.value=volumen*0.01
v.start(a.currentTime)
v.stop(a.currentTime+duracion*0.001)
}
pitar(999,220,300);
What is the problem?
This is not working on Safari.
This is not Working on chrome on iOS.
Specific errors:
Console log says for Chrome: "The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page."
It basically just works as expected on Firefox.
I tried to do it by checking if the AudioContext is available in the current browser and using a base64 encoded mp3 beep when it's not, following this older way:
How do I make JavaScript beep?
But it still won't work without the user interacting (id est. clicking somewhere on the page.)
I can somehow force the user to click once, by putting a button saying something like: "Hey, let's start".
But that will enable the click only for the first time, and not for every other minute.
I thought about creating a one minute audio file with 1 second beep and 59 seconds in silence and play it on replay. But even that would be problematic, since the beep would not be synchronized with the counter.
Another solution, would be to record a video and play that on loop.
Regarding this question - Play infinitely looping video on-load in HTML5 - it also won't work since autoplay requires muted on some browsers.
Any way of hiding the controlers and creating a custom javascript play button?
Or do you know any better way to achieve this?
Context
I am trying to loop several HTML5 videos one after the other. This is achieved via Javascript with an event listener listening for 'ended' - the video to end. At which point the url to the video is changed and video.play() is executed for the new URL.
For simplicity, lets say there are 2 videos that are to be (auto) played. After the second video finishes playing, it goes back to the first and plays that one (and the cycle continues). The videos will get cached on the user's device after they are first played.
TL-DR: Now what I want to achieve is to code a HTML5 video to be 'mobile friendly', in respect to mobile data plans.
I want the video to either stream when the page loads or buffer only a few seconds from after the point from where the user is watching. So if the user is 5 seconds into the video, the buffer extends to 15 seconds into the video (so 10 seconds of the video is buffered in case the network connection is weak). If the user pauses the video, the video stops buffering. Though the user won't have access to controls; they will be unable to forward, rewind or pause. I only gave the example of the user changing the point of the video to emphasise that I want control over how much the video has buffered and will buffer.
Alternatively, I want the video to stream to the user’s device. And only download that which needs to be immediately played. This is the less desirable option and is probably less desirable than leaving the video tag as it is since if the user has a dodgy connection, the video will play, stop, play, etc.
The reason for me wanting to achieve this is that I have noticed in Edge, IE, Firefox and Chrome that the video auto plays (good, that's what I want it to do) and plays while simultaneously downloading the whole video to their device (terrible). Of course this behaviour is expected, but practically, it should not do this. If users leave the site straight away, why would we want them to download a whole video they won't see?
Sort of but not entirely relevant, it doesn’t help:
HTML5 Video: Force abort of buffering
Simply put, the thread shows only hacks to hide the src and not any actual control over the buffer. I need to control the loading of the buffer in real time, relative to at what point the user is at, and not based on a 'pause' event. I would also like to know if there is a little-known supported method across most browsers (I only really need to worry about this on mobile) to achieve this, as opposed to a 'hack'.
Nevershowmyface: From what I can gather from the code, it stops the buffering every 0.5 seconds. There is no code for resuming the video? As for why this method will not work, it is not buffering relative to at what point the user is at. For all intents and purposes, it is still buffering the video in a linear fashion, without depending on a variable (the point at which the user is at). It's just doing it more slowly or 'in chunks'. If it loads another chunk just before the video runs out of video, I risk the video stopping and waiting to load again if the connection is poor.
Preload:none is useless here since the video is automatically played (notice bold auto at the top). I should have been more explicit. When the page loads, the video automatically plays. Preload loads the video before the play button is clicked on; preload:"none" does not load the video before play is clicked. But since there is no play button and the video plays once the page has loaded, it is a useless attribute.
My hopeless conclusion in regards to what should be a vital and basic feature
(not a rant)
From what I have found, there is no standardised way to achieve this and there are only ‘hacks’, as described in the post, which only serve to provide limited buffering functionality/ control in some browsers, potentially breaking other browsers and potentially having no effect in other browsers. In light of this, I’m on the verge of giving up on this task so thought I’d ask if anyone else has effectively managed to achieve this; it appears to have no support or has not even be considered in HTML5 or Javascript; I might be and hope I'm wrong – would be great to have this in Javascript.
Do other web developers not consider this when they use videos on their sites? I have spoken to other developers about this and they said the data usage from a site is not or is rarely the concern of the developer.
While I understand there are more important things to worry about, it goes without saying this would be very important for mobile users with low data plans.
Analysis:
The HTML5 audio element does not have a stop() function, nor does it
have an option where you can set the amount of data that it is allowed
to buffer, or a way of saying you want the element to stop buffering -
Don't confuse this with the 'preload' function, this only applies to
the element before the play button is clicked.
I have no clue why this is and why this functionality is not
available. If anyone can explain to me why these crucial functions are
not implemented in a standard that should make web development for
mobile phones better and more standardized I would love to know.
And before someone says the conclusion from that post was that this is currently impossible, note:
1) I am dealing with a video file, not an audio file. Slightly different context, where the file being buffered is significantly larger than an .mp3 file.
2) I am not trying to stop buffering altogether. I am trying to restrict it and keep it relative to the point of the video at which the user is at. So you could actually say I am trying to stop it but at an 'x' number of times after the point where the user's video is.
I've created this game using Javascript, and I play all sounds (including effects and background music) using the Audio type. It works perfectly when I run the page from my computer, but after I uploaded on my host and tried to run from the web, it started to sounds really terrible: sometimes it is delayed, sometimes it does not play at all.
I've noticed that the main problem is related to playing the same audio more than once in a short amount of time: it plays a shooting sound whenever the user clicks on the page, so usually it isn't that bad when they're not spamming their mouse, but once you start clicking many times the sounds turns out terrible.
The audio file for that particular sound is very short, and when running from my computer is has no problem even when the user is clicking very fast. Here is what the function does:
function play(aux,volume){
if(volume == undefined)
volume = 1;
if(!sound){return;}
aux.volume = globalVolume * aux.customVolume * volume;
aux.load();
aux.play();
}
So, pretty much, what it does is loading and playing the sound again whenever that function is called. That was made so it would start again even if the the function is called while the sound was still going on.
Again, this whole things works smoothly when running from my computer, but from the web it just sucks.
Q: Does anyone knows how to fix this? Or does anyone know an alternative I could use to make it work?
Suggestions are welcome as well.
Audio on the web is going through a lot of growing pains, so you might want to save yourself a bit of trouble and use Howler.js:
https://github.com/goldfire/howler.js
I'm building a winstore app and building a skip-able intro (dynamically added it through JavaScript code).
However, if i skip it and set
this.video.pause();
in the button click function, even though the video is paused, the sound of the video is still trailing for a few sec before it stopped.
How could i make the sound stop right there with the images?
It's just weird that the video is already paused but the sound still can be heard when it should've been paused too (the video contain mp4 and mp3 in it).
It's weird because if a video is really paused it off the image and sound.
You can try this following command (it cut the sound) :
this.video.setAttribute("muted", "muted");
But it's not the solution because pause() method should work, so checks if you don't have 2 videos elements in your page.
UPDATE: Have received no explanation/resolution to this issue and have reported it as a prospective flaw to Google:
https://code.google.com/p/gdata-issues/issues/detail?id=3917
I'm working on a site in which I'd like to use YouTube's HTML5 player to display sections of a video at predefined timestamps. I believe the code works correctly with the Flash player.
For argument's sake, in the referenced video, I wish to display the video at timestamps of 10s and 25s.
I think I'm doing everything correctly. The video is loaded multiple times and, "onReady", the code calls "seekTo" the timecode and then pauses the play.
Here's the code. If you're unfamiliar with JSBin, click "Run with JS" in the upper right hand corner of the "Output" screen to run it.
http://jsbin.com/ereneh/3/edit
I feel as though I've tried all permutations but I'm unable to get the video to display a screenshot of the video at the timestamps. If I manually play the video to the timestamp and then pause, it works (as expected). If I let the code run and then hit "play", the video resumes from the correct timestamp and the image appears seemingly instantly.
Am I using the API incorrectly and/or overlooking something? Is this a bug?
The console shows repeated 404s but these occur once "play" is clicked and there is no evident problem that results; the video plays as expected.
GET http://www.youtube.com/get_video?noflv=1&video_id=vn57vxP4M18&el=embedded&eurl=unknown&fmt=43&ptk=youtube_none&splay=1&start=25000 404 (Not Found)