[SOLVED] How do you play a sound?

Started by dogtanian, Sun 21/06/2015 18:10:40

Previous topic - Next topic

dogtanian

Three hours.. three HOURS I have spent trying to figure this out! I've scoured the internet and checked the FAQ and tutorial manual but I've come up empty except for a guide that is from 2004 so is a little out of date. TBH I don't understand codes and I have no interest in spending years and years trying to learn complicated stuff, but since all my "game" is going to consist of is pushing buttons to play music and video clips, it shouldn't be beyond my ability.

I have started by using the default game and I am following the tutorial, I can make a message appear but I can't figure out how to play an audio file. This is the code I have typed:
Code: ags

// room script file

function spot1_Look()
{
gold1.Play();
}



What could possibly be wrong?

Crimson Wizard

#1
The script looks fine on its own, but it's not easy to tell what may be wrong without knowing more about your project.

Most important thing is: did you actually add audio clip to the project? How it is called in the project tree exactly?

This is the excrept from the manual, explaining how sounds work:
http://www.adventuregamestudio.co.uk/manual/ags13.htm#musandsound

dogtanian

Yaay, a reply. Thankyou Crimson :smiley:

I think I added the music file correctly, in the Project Tree I right-clicked on the Music folder and added the song. The song is in the Music folder.
I changed the name to "gold1" so the ScriptName is gold1

Whatever it is I got wrong, it's very likely something embarrassingly obvious and I'm just not seeing it. I'll start fresh and follow the tutorial again.

Crimson Wizard

I do not think you will benefit of tutorial much, because it's probably not related.

You can do two things:
1) Add another command to this function, like Display, to check if it's being called at all:
Code: ags

function spot1_Look()
{
    Display("I am about to play sound!");
    gold1.Play();
}


2) Check the settings in game setup ("Build -> Build Exe" in the menu, then "Build -> Run game setup") and make sure the sound is not disabled.

Also, what is the music type you were adding (MP3, MIDI)?

dogtanian

No luck. I started from scratch (it only took a minute) and added the code; the message text appears ("I am about to play a sound!" but the sound doesn't play. It's MP3 format. I checked that the MP3 is working in AGS and it seems to be fine.

Sound is not disabled.
I think I'll call it an evening and have another go tomorrow. Thankyou Crimson.

Snarky

There used to be a problem with very short clips (or maybe clips that had certain sizes, divisible by some particular number) not playing, though I don't remember if that was for MP3 or OGG files. Could you try it with a different (longer) sound clip?

There's also stuff to do with default volumes for different sound types/clips, though it really shouldn't come into play when you start a game from scratch. Still, might be worth ruling out by changing it to:

Code: ags
function spot1_Look()
{
    Display("I am about to play sound!");
    AudioChannel* soundChannel = gold1.Play();
    soundChannel.Volume = 100;
}


If that doesn't work, we might have to look into drivers and so on. What's your OS and your AGS version?

And could you confirm that sound plays in other AGS games?

dogtanian

Thanks Snarky. :smiley:
No difference. I'm tired and I'm not quite thinking clearly at the moment so I'll try it again tomorrow when my brain is up to speed, but I did discover that when I downloaded an AGS game, when I ran the "app icon" the game had no sound, but when I ran it from the Windows exe, the sound worked fine. I don't know if that means anything.

My OS is Windows 7 64-bit and I am running AGS v3.3.3
Also, the mp3 music track I am using is about 3 minutes long.

Crimson Wizard

I suspect it does not find audio.vox for some reason, depending on how you run it.

Monsieur OUXX

At this stage I'd recommend uploading your game files so that we can try.
 

dogtanian

Quote from: Monsieur OUXX on Mon 22/06/2015 16:03:51
At this stage I'd recommend uploading your game files so that we can try.

Thankyou Monsiuer. I don't really have anything much to upload, but here it is: http://s000.tinyupload.com/?file_id=83774531228068138218

Crimson Wizard

I compiled your project, and I can hear the gun-shooting sound whenever I click with Eye cursor.

E: there is something wrong with compilation though, when I compile and run for test (F5) Editor freezes for several seconds. It does not do so when I do Build -> Build EXE.

Khris

Works fine for me, too. No freezing either.

dogtanian

#12
Thankyou Crimson and Khris. I believe I have made some progress. :)
I ran the "Build EXE" and then ran the "Run Game Setup" and changed Digital Sound from "Default Direct Sound Device" to "Default Wave Out Device" and when I ran it, the sound worked! I really don't have much of a clue what any of that means, I just pressed the buttons at random and crossed my fingers.

So now I'm wondering, is there a way to keep AGS in that "Default Wave Out" mode? At the moment I can only get the sound working when I use the "Run Game Setup". I'm guessing it's something to do with my Xonar DS sound card, I bet the program would work normally if I was using onboard sound.

A second minor issue (at least I hope it's minor) is that I selected the "Any Click" for the hotspot, but it only works with the "Eye" icon.

EDIT* Oh.. wait a sec, it continues to work! I now have sound! (nod)
Okay, so if I run Game Setup and select Wave Out Device before I start on a project, that should fix my problem. :cheesy:

Thankyou again to Crimson Wizard, Khris, Monsieur OUXX and Snarky.

Crimson Wizard

Well, that would explain it.

The setting you are speaking about is not the project setting, but runtime configuation of the game. Game itself will not "remember" it unless you copy acsetup.cfg file over. Normally you need to run setup and modify settings yourself for every game's installation.

I would suggest you to change it back to Direct Sound when you will distrubute your game, because that's the default setting for most of the users.

SMF spam blocked by CleanTalk