Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Playing Audio Using Keystrokes: Is It Possible?

Annabelle5893

Gold Coder
I'm wondering, how would I make an app that plays audio files using the keys on the number pad? Specifically, I want to make an app that triggers "Rotary Pulse 1" by pressing 1 on the numeric keypad, all the way up to "Rotary Pulse 0" on the 0 key. A dial tone will be toggled on by pressing the spacebar, which will begin with a "receiver pickup" noise. The dial tone turns off when digits are dialed via the numeric keypad. If you press the spacebar either when the dial tone is on, or after dialing a number, a "Receiver Hang Up" noise will be triggered. With the rotary dial sounds, the dial turning to the fingerhole is triggered at key down, and the release of the dial returning to the resting position will be triggered by releasing of the number corresponding to the fingerhole (1, 2, 3, 4, 5, 6, 7, 8, 9, 0). This will be accompanied by the internal sound of the dial pulses as heard in a telephone. What is the code I would use to make this audio app using HTML?
 
It seems I can manually trigger the playing of files by pressing the "Play" button next to them on the "Info" page's "Media" tab in Firefox. However, I can't seem to get anything to play when pressing any keystrokes. What did I do wrong? View attachment 2500
Hey there,

I am still working on a work around for you so you are able to play the sounds automatically. Unfortunately, it has taken me a bit longer than I had mentioned, one with life, and two, with this new security measure the browsers have implemented.. a bit of a pain in the you know what lol. I will send you the file when I have it ready
 
Hey there,

I am still working on a work around for you so you are able to play the sounds automatically. Unfortunately, it has taken me a bit longer than I had mentioned, one with life, and two, with this new security measure the browsers have implemented.. a bit of a pain in the you know what lol. I will send you the file when I have it ready
Hang tight. I also moved some stuff around in the script and cleaned it up a bit... I think once I find that work around for you, it should be smooth sailing
 
And once you put it up then I could copy all the new changes into my page? Would I have to delete all the HTML and script that's full of errors and just put the new stuff in there?
The plan is to change as little as possible so that this solution works with the html you already have. There may be slight changes to the html, but nothing too drastic. The script itself, you may need to delete what you currently have before pasting the new version over.
 
Any new updates yet?
Hi there @Annabelle5893,

Thank you for being patient. I do have a bit of an update for you. So after quite an extensive bit of research, unfortunately, there would be no way to have some of the functionalities you are wanting to have as far as autoplay without interacting first with the page. I am currently implementing a modal that would pop up when the page refreshes. This would be to change the policy so that once you click on accept, and allow somewhat of autoplay. I will upload my changes here by latest Sunday night. Gotta love Google for wanting to implement this and all other browsers following suit all in the name of "user experience"
 
Hi there @Annabelle5893,

Thank you for being patient. I do have a bit of an update for you. So after quite an extensive bit of research, unfortunately, there would be no way to have some of the functionalities you are wanting to have as far as autoplay without interacting first with the page. I am currently implementing a modal that would pop up when the page refreshes. This would be to change the policy so that once you click on accept, and allow somewhat of autoplay. I will upload my changes here by latest Sunday night. Gotta love Google for wanting to implement this and all other browsers following suit all in the name of "user experience"
A modal? Is that like a dialog box?
 
So what you're saying is, this modal dialog that pops up is like a license agreement? I'm confused!
Kind of sort of. So according to Google's own documentation, this change in the autoplay policy is intended to not only give users a better user experience, but reduce data usage/consumption so that it doesn't become a bottleneck for a network, discourage users from installing ad blockers. This was supposedly only going to be just on Google Chrome, but other browser vendors decided that it was a "great idea" (note my overly exaggerated sarcastic tone with that one lol) so they have also implemented these changes as well. So now by default, browsers will disable autoplay, and the only way to get to autoplay to work is to do one or more of the following:
As per Google's docs
  • Muted autoplay is always allowed.
  • Autoplay with sound is allowed if:
  • Top frames can delegate autoplay permission to their iframes to allow autoplay with sound
So now for the fun part. As I was doing my research I would add and test potential solutions. Unfortunately, if you call click() on an element will not work because that is simulated user interaction. I also tried to add a delay before the click() event, to make it more "human-like" and still did not work. The only way for it to work is to actually move the mouse and click, or hit a key on the keyboard. So the idea behind the dialog box is the following:
1. have the dialog box pop up when the page loads. This will have some text like "This feature has some audio that requires autoplay. Please click 'Accept' to enable autoplay on this browser. "
2. Once the 'Accept' button is either clicked on with a mouse, or activated with the press of the Enter key, this will count as user interaction and thus will enable the autoplay.

I decided to go down this path because the other solution of using an iframe would mean adding more code and changing more of what you already have in place.
 
Kind of sort of. So according to Google's own documentation, this change in the autoplay policy is intended to not only give users a better user experience, but reduce data usage/consumption so that it doesn't become a bottleneck for a network, discourage users from installing ad blockers. This was supposedly only going to be just on Google Chrome, but other browser vendors decided that it was a "great idea" (note my overly exaggerated sarcastic tone with that one lol) so they have also implemented these changes as well. So now by default, browsers will disable autoplay, and the only way to get to autoplay to work is to do one or more of the following:
As per Google's docs
  • Muted autoplay is always allowed.
  • Autoplay with sound is allowed if:
  • Top frames can delegate autoplay permission to their iframes to allow autoplay with sound
So now for the fun part. As I was doing my research I would add and test potential solutions. Unfortunately, if you call click() on an element will not work because that is simulated user interaction. I also tried to add a delay before the click() event, to make it more "human-like" and still did not work. The only way for it to work is to actually move the mouse and click, or hit a key on the keyboard. So the idea behind the dialog box is the following:
1. have the dialog box pop up when the page loads. This will have some text like "This feature has some audio that requires autoplay. Please click 'Accept' to enable autoplay on this browser. "
2. Once the 'Accept' button is either clicked on with a mouse, or activated with the press of the Enter key, this will count as user interaction and thus will enable the autoplay.

I decided to go down this path because the other solution of using an iframe would mean adding more code and changing more of what you already have in place.
Interesting. So if I were to eventually turn this into a desktop app, would it still have the same crazy error? That would be a pain in the padded rear!
 
Interesting. So if I were to eventually turn this into a desktop app, would it still have the same crazy error? That would be a pain in the padded rear!
Unfortunately, from what I see, that may be the case. There are ways to disable these autoplay policies if this was something that only you would be using. However, if you ever decide to make your application available for the public, then yes, this will be a big major pain in the rear due to:
1) Asking users to disable autoplay policies that they themselves aren't aware of, especially if they are not tech savvy, is already a challenge in it of itself.
2) You may get a lot of pushback from those that are either really tech savvy, really privacy oriented, or both.
3) Disabling these autoplay policies at a system level means that autoplay is now enabled, which means it may cause major annoying issues for those that don't want everything autoplayed.

Don't get me wrong, I believe that the solution I am working on for you for this version of your application will definitely get around the issue of autoplay, and if you decide you want to turn this into a desktop app, you may need to implement similar logic for it. As far as the potential for your application to be made available for the public, this would be the better route. Making sure that your users understand what is going on and making sure that they are aware that this application will be the only thing to bypass those policies will be key.

Welcome to the wonderful life of being a software developer lol.
 
I wonder if this autoplay policy error is true of any apps that are coded to play audio.
It seems to be the case, based on what I have read. With that being said... I have something for you :). I do apologize for the late reply. Been sick and taking a rest. Attached is the changes I made to the html file.
 

Attachments

  • Virtual Touchtone Phone.txt
    22.1 KB · Views: 1
I fixed it, but now the only sound that plays right away is the "Ringing Tone". I can't get the others to play by pressing any keys. What do I do next? For example, I press Enter to toggle the "Hookswitch", but it doesn't do anything.
 
I fixed it, but now the only sound that plays right away is the "Ringing Tone". I can't get the others to play by pressing any keys. What do I do next? For example, I press Enter to toggle the "Hookswitch", but it doesn't do anything.
Hmmm. Let me see on my end if there are any errors that pop up when pressing keys. I didn't test that out. I think it may be that your file paths may be erroring out.
 

New Threads

Buy us a coffee!

Back
Top Bottom