Page 1 of 2

Getting audio to work?

Posted: Thu Mar 29, 2012 12:09 am
by Yousar
Sorry, I'm really new to scripting but this is confuzzling.
https://love2d.org/wiki/Tutorial:Audio
I understand the script and all, but where do I put it?
In an audio.lua file, or a main.lua file?
How do I load it?
I wish these tutorials were more helpful.
That or I'm just dumb.

EDIT:
Here is the error:
Error
audio.lua:1:Could not read Ogg bitstream


Traceback

[C]: in function 'newDecoder'
audio.lua:1 in function 'newSource'
music.lua:1: in main chunk
[C]: in function 'require'
main.lua:5: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'

The code is basically copied from https://love2d.org/wiki/Tutorial:Audio and https://love2d.org/wiki/Tutorial:Hamster_Ball.

Audio is in music.lua, hamster ball in main.lua

Re: Getting audio to work?

Posted: Thu Mar 29, 2012 1:12 am
by baconhawka7x
I'm not too experienced with love.audio. But Are you requiring all of the files that aren't main.lua or conf.lua?

Code: Select all

--the top of main.lua
require "music.lua"


--everything else below the top of main.lua

Re: Getting audio to work?

Posted: Thu Mar 29, 2012 1:36 am
by Yousar
I have required the code.
And I have changed the music code to this:

function love.audio()
music = love.audio.newSource("hurricane.ogg") -- if "static" is omitted, LÖVE will stream the file from disk, good for longer music tracks
love.audio.play(music)
end

It's in music.lua

EDIT:
Now that I have changed it, the error is:

Error

Boot.lua:1: attempt to index file 'audio' (a function value)

Traceback

[C]: in function 'xpcall'

Re: Getting audio to work?

Posted: Thu Mar 29, 2012 1:44 am
by baconhawka7x
You should but your code inside if the code tags.
But more importantly, your putting all of that inside of function love.audio() which is incorrect.
you're doing..

Code: Select all

function love.audio()
   music = love.audio.newSource("I forgot what this was.ogg")
   love.audio.play(music)
end
but you shouldn't but all of that inside of function love.audio() just put it all inside of love.load() and it should work.

Re: Getting audio to work?

Posted: Thu Mar 29, 2012 2:22 am
by Yousar
Thanks, there is no error now but I can't hear anything.
=(

Re: Getting audio to work?

Posted: Thu Mar 29, 2012 2:43 am
by baconhawka7x
Hmm..
love.audio.setVolume(1.0)
maybe, if that doesn't work, then upload a .love

Re: Getting audio to work?

Posted: Thu Mar 29, 2012 3:02 am
by Yousar
How do I upload my .love file?
Sorry, I know this sounds really stupid but I don't know about uploading files.
Also, if it helps...
I changed the audio from .mp3 to .ogg

Re: Getting audio to work?

Posted: Thu Mar 29, 2012 4:14 am
by tentus
To upload a .love, select all your files, and zip them up (how to do this depends on your operating system). Then, rename the .zip file to .love (.love == .zip)

Then, click reply. Underneath the reply text area, there are two tabs: Options and Upload Attachment. Click on Upload Attachment and browse to the file, and then click "Add the file".

Re: Getting audio to work?

Posted: Thu Mar 29, 2012 5:26 am
by Yousar
Thanks.
I have uploaded it now.
See if you can understand why it isn't working...

Re: Getting audio to work?

Posted: Thu Mar 29, 2012 9:37 am
by baconhawka7x
You should only be using love.load() once, inside of main.lua. The .ogg is making the .love too big to upload:(
But, it still doesn't work. Your .ogg file is broken for some reason:p So try a different .ogg.(My guess, is you got a different type of file, and then tried just renaming it to .ogg(i.e, it was a .mp3, but you just renamed it to a .ogg(that doesn't work)))