0

I create the folder sdcard and a subfolder audio (sdcard/audio) inside my project in eclipse. The sdcard folder will be locaded under the res folder. I then copy an mp3 file to the audio folder (sdcard/audio/sound.mp3).

What I'm wondering is, will this mp3 file be included in my project? I.e. when a user downloads my app, will they get mp3 file as well? And will it be reachable in their device though this path: Environment.getExternalStorageDirectory().getPath() + "audio/sound.mp3" ...

If this is not so, than how and where should I include audiofiles? In the assets folder maybe? I already tried to include them inside res/raw and that works. But from what I understand, only sounds like alarms and other small sounds should be there.

Gravitoid
  • 1,294
  • 1
  • 20
  • 20
user3711421
  • 1,658
  • 3
  • 20
  • 37
  • `located under the res folder` ? You mean you created a folder IN the res folder? So finally you have res/sdcard/audio/sound.mp3 – greenapps Jul 01 '14 at 21:39
  • No, it is not in the res folder, it is sdcard/audio/sound.mp3 .. Ascorbin first adviced me to use assets to save my audiofiles. After some second thoughts i think it dosent work as i thought.. I had hoped that by adding the folder sdcard and put audio files in it. Than the files in it would be created on the users sdcard on install. – user3711421 Jul 01 '14 at 21:48
  • So it is Workspace/Project/sdcard/audio/sound.mp3 And sdcard folder is on the same level as the res folder. And sdcard alphabetically comes after res. – greenapps Jul 02 '14 at 08:27
  • yes its on the same lever, and yes it comes after bc 's' is after 'r'. – user3711421 Jul 02 '14 at 09:16

1 Answers1

0

will this mp3 file be included in my project? I.e. when a user downloads my app, will they get mp3 file as well?

Yes.

will it be reachable in their device though this path: Environment.getExternalStorageDirectory().getPath() + "audio/sound.mp3" ...

Definitely not. Fortunately the internal structure of your project is not mapped to the file system of the user's device.

This question should give some clarification on the difference between /res/raw and /assets and I think the assets folder is the right choice for your mp3.

Community
  • 1
  • 1
fweigl
  • 21,278
  • 20
  • 114
  • 205
  • Many thanks for a fast reply :). I am confused about the sdcard thing though. Just to clarify, i created the sdcard folder by right clicking the project than >new>folder. So i didnt create it by code. And, if i could add files to the sdcard this way. How could i than access these files from my code? I though i could access it (audiofile now) by: mediaPlayer.setDataSource(Environment.getExternalStorageDirectory().getPath() + "audio/sound.mp3"); ?? – user3711421 Jul 01 '14 at 21:07
  • No, those are entirely different things. getExternalStorageDirectory().getPath() gets you the path to the sdcard on the device, this has nothing to do with the structure of your project. If you created a folder called 'sdcard' within your app project, I wouldn't know how to adress it from within your app. But it doesn't make sense really. – fweigl Jul 01 '14 at 21:11
  • So you do recommend me to put the audio files in the assets folder? There will be at least 40 audio files, each about 0.5-5mb. The path to the file will be in a database. I though putting them on the sdcard would be the way to go. – user3711421 Jul 01 '14 at 21:14
  • Wow, this sdcard thing has really messed up my day. I though creating the sdcard folder inside my project would be similar to create the raw folder inside res. – user3711421 Jul 01 '14 at 21:15
  • I can't recommend you on that to be honest, but I'm sure there are resources out there that would advise you on how to store large chunks of data / files. I know that you can specify the place where your app will be installed so you dont take lots of their internal storage with your mp3s: http://developer.android.com/guide/topics/data/install-location.html – fweigl Jul 01 '14 at 21:24
  • Okey, but assets seems to be the way to go. ARE you sure that the answer to the first question is YES? This is confusing me quite a bit.. Read the Sentence after the ? "when a user downloads my app, will they get mp3 file as well?" – user3711421 Jul 01 '14 at 21:59
  • At the moment it is irrelevant if it is packed with the apk as it will be unreachable. I suppose it is not packed. But you can find out yourself as the apk is also a zip file. Unzip it to see if it has mentioned `sdcard`somewhere. You could also compile an apk with and without a mp3 file in that folder and see if the size changes. – greenapps Jul 02 '14 at 08:31
  • This is what i did and the mp3 is not included. So the only way to manually add data to the app is by either putting it in the assets folder or in the res folder. To put data in the sdcard that the app later could use, would only be possible if the app transfered data from the assets to the sdcard. Or you had your app first create a folder on the users sdcard than make the app fetch data to that location from the internet. – user3711421 Jul 02 '14 at 09:30
  • You are right and my answer, as far as I can see, was wrong in the first part. Creating some folder in the project and putting files in there doesn't mean they're included in the .apk. Would be interesting to dive into what exactly happens when the apk is compiled. But you have two folders to put your mp3s in :) – fweigl Jul 02 '14 at 21:29