Why should I keep audio and video files inside the raw folder?

Asked

Viewed 278 times

2

On Android you have inside the directory res several subdirectories, apparently separate, for better organization. Sometimes when you want to put a new audio, for example to touch, other than device patterns, it is advised to put in a folder called raw.

Why should I keep audio and video files inside the folder raw? Is there any special treatment so we have to keep them inside this directory? Is there any consequence or loss of performance when placing an audio file inside the directory drawable?

1 answer

3


Android SDK tools compile features(Resources) together with the application torque(1). During this process symbols (class R) are generated for each one, in order to be accessed in the code.

The R class contains code for all resources in the folder res/. For each type of resource, there is a subclass R (R.drawable, R.layout, etc.) and, for each resource of that type, an integer (id) identifying it.
The id is used, in the code, to reference it, when you want to use the resource.

To allow this mechanism Android has a predefined folder structure and requires each resource type to be placed in the respective folder of this structure.

So it’s not a matter of "must" or "performance" but yes the way Android treats the features of the application that requires each type of resource is placed in the respective folder.

(1)
- The files placed in the folder res/raw are not compiled, only entries are generated in class R.
- The files placed in the folder java/Assets are not compiled and no entry in class R will be generated.

References:

  • Considering the phrase "Files placed in the res/raw folder are not compiled[...]", then if I put an audio file in the directory, for example layout, will that file be compiled? Or media files are not compiled in any way?

  • 1

    Gradle will not allow an audio file to exist in the folder layout. Try it and see what happens.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.