If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

autoplay audio after keystroke

hi there! I'm creating a task where I would like the screen to show a succession of presentations where an image appears and an audio clip automatically plays (with no display of the audio player). The user would then advance to the next presentation by pressing a key. I currently only have the image part, and am having trouble with the audio. I'm new to programming so any help would be greatly appreciated!! THANK YOU in advance! Here is what I have so far:

Here's a little function I wrote: http://pastebin.com/GKRx0GDk
It works in HTML5. Just pass it a source url (local or remote, don't forget the protocol http/file) and it should play the file, assuming your browser can handle the file format you passed it.
It's ok to have spaces in the source url too, in-case you were wondering. They just get converted to %20

So how does this fit with my current code? Will it prevent my functions from working? Where would I insert your code?

It won't prevent anything from working. Place the function at the beginning of your script tag, then just call play() wherever you want it to play. You said you wanted it to play after they pressed a key, so put the function call right after where you advance to the next presentation.

You said you wanted it to play after they pressed a key, so put the function call right after where you advance to the next presentation.

Thanks so much for your help!! I'm still a little bit confused

https://qtrial.qualtrics.com/SE/?SID=SV_bvZZ3S3cfitkOUt
^^^
This is an example of what I'm trying to do, except when you see the picture or word, a short audio clip will play in the background at the same time. Then after you press the correct button (E or I), it will move to the next word or picture where the same thing will happen but with a different audio clip. How would I go about doing this with the function that you wrote and combining it with what I have so far?

Your code is so confusing to me that I don't know what to recommend. You seem to use a lot of arrays, so maybe make a new array containing a right & wrong for each presentation, just like you do for the right & wrong keys.

I'm not too familiar with the html5 audio tag, you may want to read up on it. I know it can accept mp3, wav, and ogg. Maybe others, not sure.

As for the code... you can take my function and paste it before your code (at the beginning, inside your &lt;script&gt; tag). Then you'll be able to use play() anywhere inside of it. Maybe you can have some arrays with different audio file urls that play whenever you need them.