Where to store sound files in the project and what solution to chose for storing references to them?

StackOverflow https://stackoverflow.com/questions/9166480

Domanda

I'm making some fancy app which requires lot of short sounds for its use. Got few questions You might be able to answer.

  • Is there some restriction to the place I store then in the android project? Currently I put those in bin/res/sounds folder.

  • Is there a restriction to the format of files and is the .wav ok?

  • I'm gonna need something to store references to those sounds. I came up with a Dictionary which would consist of a sound name (key) and a path to the file so I could use in such method:

    mp = MediaPlayer.create(Test.this, R.raw.mysound);

How should I store R.raw.mysound, it's not a string right?

I apologize If i'm not quite clear about everything, I'm trying my best. Cheers

È stato utile?

Soluzione

Usually, you'll store sounds in the raw folder under your res folder (res/raw/mySound.wav). This tells the OS not to mess with it and just copy it over for you. Then you can use the line of code that you posted to load them in.

As for the .wav format that will work fine but it will be really large.

Have a look at what audio formats Android supports: http://developer.android.com/guide/appendix/media-formats.html

The reference (i.e. the R.raw.mySound) in an int. So you can just map some string to that int if you want but is that really easier than using the R.raw.mySound id?

Altri suggerimenti

They don't belong in /bin, because that is an automatically produced build directory. They do belong in /res/something, which may be what you mean.

R.raw.mysound is an int, as are all R.* references.

.wav files are fine, although big. Anything else and you will have to check both what was supported on your target platform, and whether all devices are likely to support it too. For instance, in the early days of Android, the platform specified several types but some were optional and up to the device as to whether they supported it. For a full list see: http://developer.android.com/guide/appendix/media-formats.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top