#On what exactly I dont even know what to

1 messages · Page 1 of 1 (latest)

west plaza
#

what about this do you not understand

void Start ()
     {
         //AudioClip selectedClip = clips [Random.Range (0, clips.Length)];
         WWW audioLoader = new WWW ("file://" + musicDir + "//clip.wav");
         AudioClip selectedClip = audioLoader.GetAudioClip (false, false, AudioType.WAV);
         source.clip = selectedClip;
         Debug.Log (source.clip.name);
     }
charred current
#

for example, why do we need to import networking?

west plaza
#

because you need to use the WWW class and that is in networking

charred current
#

what does WWW do specifically?

#

if I'd try to google that itd just say world wide web

west plaza
#

in this case it loads a file from disk

#

do you see the file:///

charred current
#

yes

#

Why is it so much more different from converting an image to a sprite?

west plaza
#

because music files are very difficult to load from raw bytes

charred current
#

hmmm

west plaza
#

this was from the first example on the link I sent you. It uses the WWW class which is now outdated.
you would be better looking at the second example which uses the UnityWebRequest class as that is the current way of doing things.
btw you could also use this to load your image files

charred current
#

The image files are loaded in flawlessly with your system so I will not change that

#

But yeah I never did anything like this before

west plaza
#

So you need to google UnityWebRequest and read it and follow the links in the documentation

charred current
#

This one?

west plaza
#

yes, it's very simple really

charred current
#

It looks simple

#

But for some reason my brain is failing to process how I should add this to my AudioManager

#

thats what an all nighter does to a man

west plaza
#

Firstly I would forget the async stuff in there for now
So try to make the LoadClip method then show me what you have done

#

I am not going to spoon feed you so dont expect it

charred current
west plaza
#

says the man who does not know how to google

charred current
#

dude its not that i dont know how to google

#

i dont know how to understand code from google

#

If I was one of those people I'd just instantly paste the first result into my script

#

But I am trying to actually understand how it works

#

Thats what learning is about

west plaza
#

In that code block

UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.WAV)

is the important bit so that is the documentation you should be reading

charred current
#

Just UnityWebRequest?

#

Also sorry im not responding too fast, I am just focusing on quickly fixing my UI

west plaza
#

and the bit after the =

#

UnityWebRequestMultimedia.GetAudioClip
doesn't that sound interesting considering you want to read an audio file?

#

you should not be responding fast, you should be reading what I type and directly going to find the relevant unity documentation

charred current
west plaza
#

read the docs, it will show you not only what you want to do now but also what you may want to do in the future

#

this is where docs are better than tutorials

charred current
#

Should I make a different script for this or should I write it in my AudioManager simply?

west plaza
#

in audio manager

#

you just need the LoadClip method without the async

charred current
#

and what does async do specifically?

#

I dont understand the word asynchronous

west plaza
#

normal programs run synchronously, that is line by line
asynchronous methods run as a separate thing, like a coroutine, they do their work without blocking the main synchronous thread. It is a way of getting slow work done (like loading files) without affecting the performance as far as the user is concerned

charred current
#

I see. Thank you

#

Also, what do I need to import for Task<>

#

Networking isnt enough

west plaza
#

task is part of async, you dont need it

charred current
#

So just async LoadClip()

west plaza
#

no, think about it

#

what should your method return when it is done?

charred current
#

An audioclip

west plaza
#

so what goes in front of LoadClip?

charred current
#

But then what do I need to import?

charred current
#

cant be it

west plaza
#

what did you want back again?

charred current
#

An Audio Clip.....

west plaza
#

so how do you write that in code?

charred current
#

I have to think about this hold on

#

I dont even know my imports bruh

#

this is embarrassing as all hell

west plaza
#

it's there for you

async Task<AudioClip> LoadClip(string path)

what is left if you remove async and Task<>
ffs

charred current
#

LoadClip()

#

but thats a method?

west plaza
#

no read carefully what I wrote

charred current
#

AudioClip LoadClip(string path)

west plaza
#

finally

charred current
#

But I have the Audio library imported

#

And I still get errors

west plaza
#

did you check the namespace for UnityWebRequest?

#

do you have that in a using?

charred current
#

havent even written the WebRequest part yet

west plaza
#

show what you have

charred current
#

hold on

#

im being dumb

west plaza
#

probably

charred current
#

Alright, so

#

1 error, 2 warnings after I effectively copied in the code

#

await can obviously only be used in an async method

#

and warnings about logging the errors

west plaza
#

yes, like yield in a coroutine

charred current
#

Also, does this mean that I'll only be able to check for .WAV files?

west plaza
#

so if you look at this

while (!uwr.isDone) await Task.Delay(5);

what needs to be removed ?

west plaza
#

no

#

because you have to wait until the file is loaded somehow

charred current
#

I just dont know how

west plaza
#

this is where you go and check the documentation on the isDone bool

charred current
#

await Task.Delay() needs to be removed

charred current
#

And that we need the program to halt until it finishes

west plaza
#

so what should your while do if the request is not finished?

charred current
west plaza
#

you do not want to halt, you want to just wait

charred current
#

How exactly?

#

time.DeltaTime?

#

nah thats dumb

#

I dont know what method to use in that case

west plaza
#

This is using a coroutine

charred current
#

Ah yeah I was about to say

#

So we just start a coroutine?

#

also quick question

#

will this need the user to be connected to the internet?

west plaza
#

no

charred current
#

Alright perfect

#

Just because it says that it downloads an audio clip

west plaza
#

because the url you will use will be file:///
you do know what a url is dont you

charred current
#

ofc

#

its just an adress

west plaza
#

and you know you can load a local file into a web browser?

charred current
#

Of course

#

I messed around with html before

west plaza
#

then why the stupid fucking question?

charred current
#

I was just confused about the download part, is all

#

no need to get angry

#

its just phrased in a way that I didnt get at first

west plaza
#

sorry, but you are being really dense

charred current
#

sadly you're not making it easier on me either when you respond like that

#

But I understand

#

I appreciate you helping

west plaza
#

if you know wat a url is and you know the file:/// protocol then why ask if an internet connection is required

charred current
#

Because of the Create a UnityWebRequest to download an audio clip via HTTP GET and create an AudioClip based on the retrieved data. part

west plaza
#

and ?

charred current
#

It wasnt obvious at first

west plaza
#

HTTP get works with file:/// protocol

charred current
#

ive heard way too many methods of doing this using a server domain

#

I dont wanna get jumbled up in those

#

And have to pay for a server just to make pong use funny sounds.

#

So I'm just trying to make sure that everything is solid

west plaza
#

you have so much to learn, thank god you are not targeting Android or WebGL

charred current
#

That's... why I'm here, yknow.

#

To learn

#

This thing is one of the most niche things that you can do

#

But I thought itd be a fun project

#

instead its just becoming this

west plaza
#

I have to say you do not make it easy on us when we try to help you

charred current
#

If it's hard for you to handle "stupid questions" then yes, its not easy

#

trust me, I have very shitty patience too when it comes to things I'm experienced with

west plaza
#

Anyway back to the problem at hand
Delete your loadclip method and replace it with the GetAudioClip method from the example

charred current
#

Which example are you refering to?

#

We have 2

west plaza
charred current
#

Just completely replace it?

#

The url is gonna be the path so I will just type Path.Combine etc...

west plaza
#

yes, replace it, we will come to the path shortly

charred current
#

somethings not right

#

I dont think that the AudioManager is the right script to write this in

west plaza
#

why not?

charred current
#

"clip does not exist in the current context" in AudioClip s.clip = DownloadHandlerAudioClip.GetContent;

west plaza
#

wtf did that come from
I have

IEnumerator GetAudioClip()
    {
        using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("https://www.my-server.com/audio.ogg", AudioType.OGGVORBIS))
        {
            yield return www.SendWebRequest();

            if (www.result == UnityWebRequest.Result.ConnectionError)
            {
                Debug.Log(www.error);
            }
            else
            {
                AudioClip myClip = DownloadHandlerAudioClip.GetContent(www);
            }
        }
    }

from that documentation page

charred current
#

My bad

#

Thought I have to replace it

#

Okay soo

#

Now

#

I actually have no clue what to do next

west plaza
#

so now, are you getting a file name from the user, are you getting an extension as will or are you using a fixed file type

charred current
#

id want any extension

#

I dont see the reason in limiting it only to one specific type

west plaza
west plaza
charred current
#

Fair I suppose

west plaza
#

this is the point when you google 'Unity AudioType'

charred current
#

I actually dont know the difference between mp3 and wav and all the types besides compression, but it doesnt matter anyway rn

west plaza
#

oh yes it does

charred current
west plaza
#

you need to tell Unity what type of file it is dealing with

charred current
west plaza
charred current
#

jesus

#

calm

#

I wasnt being serious

west plaza
#

this is why you are not learning, you are always looking for the easy way out

charred current
#

no I'm not??

#

What

#

If I was looking for the easy way out I would be done with it already

#

But I am trying to fucking understand

#

So I have to worry about this less if I ever have to do it again

#

Which I probably wont

west plaza
#

Did you google Unity AudioType? and look at the doc page

charred current
#

Yes I am doing that rn

#

There is literally no difference between that and what VS Community is telling me though.

west plaza
#

I beg to differ

charred current
#

They say the exact same things in the descriptions for me

#

I am looking at them one to one

#

Not a single letter differs

#

It is the easy way out in the sense that I dont have to wait 10 minutes for chrome to boot up so I can check the exact same thing, thats 100% correct

charred current
west plaza
west plaza
#

A lot of the time that gives additional information and examples (not in this case) but very often

charred current
#

Exactly

#

Other times I use the documentation obviously

#

But in this case its literally 3 words

#

with no explanation

west plaza
#

Doesn't matter, what does matter is you need to know the file type you are trying to load

charred current
#

Other times I only use the VS snippets when I'm trying to find something that COULD help

charred current
#

So like MPEG and WAV?

west plaza
#

of course, if you program it that way

charred current
#

i just dont know how to honestly

west plaza
#

lets just stick to MPEG for now, you can always expand this later

charred current
#

i was thinking of saying it like AudioType.MPEG || AudioType.WAV

#

its a bool, so yknow

#

i think that makes sense

west plaza
charred current
#

Oh hold on

#

I was looking at stream

#

Whoops.

#

That was a different docs site

#

well anyhow

#

im gonna have to call it here

#

Look dude

#

Thank you so much for the help

#

But if I really do trigger you with "stupid questions", please dont stress yourself about it

#

While I do appreciate someone helping

#

I also dont want you to waste more energy on me than you expect

west plaza
#

I have been doing this for 45 years, I think I can handle the stress

charred current
#

I am quite sure we've met before

#

Like a year ago or so

#

I was even more stupid back then

#

Trying to bruteforce a game

#

By copying every single docs site ive seen

charred current
west plaza
#

Stress is my middle name, where to do think the SSS comes from

charred current
#

There are multiple ways of handling it, some better, some worse, some easier, some harder

#

Hell if I know. At one point I resorted to masochism

charred current
#

Yeah, just keep your guard up

west plaza
#

Anyway, do what you need to do and ping me tomorrow then we can continue the master class

charred current
#

I know that my shitty personality can fuck with people's expectations

west plaza
#

I dont think there is anything wrong with your personality, but you do seem to have serious learning problems

charred current
#

Well, that's just beating around the bush

#

I can go from understanding 4D objects to not knowing how to rotate a rectangle in 2D

#

I learn things which I think I will need

#

Instead of trying to be streamlined

#

I just jump to whatever seems to be the most important

#

Of course, that can lead to me missing 1 or 2 less advanced stuff

#

but thats me

#

Anyhow, thanks for the help again

#

Sorry for the trouble

#

I didnt get to test to see if it works

#

But tommorow I'll try to code it in

west plaza
#

it wont work, it is far from ready to work

charred current
#

I know

#

Still needs to be able to get a filename

west plaza
#

and a file type

charred current
#

And things like that yep

charred current
#

Whatever

west plaza
#

you can

charred current
#

Main thing is

#

I have 5 sound effects

#

That need to be customizable

#

And they are stored inside an array

#

Instead of being hard coded

west plaza
#

say I have a file
mysound.mp3
and I rename it
mysound.steve
is it still an mp3?

charred current
#

So tommorow I'll just look into thag

west plaza
#

yes it is

charred current
#

I mean

#

You can convert the extension back

#

But with the wrong extension it wont do anything

#

The info inside doesnt change

#

Only the way the system interprets it

#

Correct?

west plaza
#

of course it can.
I think you need a course on Windows file management as well

charred current
#

._.

#

cant blame me for having my teachers teach me a c++ c# sql html python hybrid shit instead of actual code also

#

and actual logic

#

sure its a pseudocode

#

but it doesnt help matters

#

Out of 26 people I was the only person in my class who knew how to write actual code that can be compiled

#

Pretty sad, seeing that im majoring in maths and informatics

#

but what can ya do

#

I don't care about being called stupid as long as I can help people become smart

west plaza
#

That is a very sad state for your education system t0 be in

charred current
#

Like using == instead of = in an if statement

full jasper
#

Jeez this was a long thread for loading up an audio file Tatu_shock

charred current
#

Because its a comparation and not a declaration

full jasper
#

What specifically were you trying to do again?

west plaza
full jasper
#

I do not I just was surprised to see this thread active still

charred current
west plaza
#

we are having some conceptual problems

full jasper
#

Ohhh right

charred current
#

At least we know that this is rock bottom

#

it only goes up from here

full jasper
#

I can see why that would require "networking" in that you need to use a certain class for file management

west plaza
#

even though, in this case it is not 'networking'

charred current
#

Yeah I didnt understand why it required networking when converting an image file to a sprite didnt

#

I like to know the specifics

#

I get told that im a fucking moron a lot for it

#

But I like to know all parts of everything

full jasper
#

Audio is weird, unlike a picture that can just be an array of rgb values, audio files are all weird frequencies that go back and forth with multiple channels, it can get wacky!

west plaza
full jasper
charred current
#

A teacher of mine told me that I am a very incompetent child just because I asked where the quadratic formula came from

#

Like how it was made

#

Made me have to learn the entire thing

#

Cried that day

full jasper
charred current
#

It was some old ass teacher

#

Thinking he is hot shit

west plaza
charred current
#

Thank fuck I never have to see that dude gaain

#

Made my passion for math weaken so bad

#

I was considering if I should even try majoring in maths and informatics

full jasper
#

Sorry you two had a miserable experience in school

#

Jeez

charred current
#

Now I have a better teacher

#

If I miss a lecture for some reason she literally just allows me to have a personal class with her after class hours are over

#

And just explain the things

#

So at least things are better now

#

(besides the fact that the entire school is in a different language than my native, so I have to learn it if I want to understand)

#

Anyhow

#

Gotta go

#

See y'all later!

#

And thanks again