Directory for storing audio files in Android

守給你的承諾、 提交于 2019-12-02 16:37:30

dont put the media files inside res/

Put your files(temp.wav) in a folder named /sdcard/audio(if you are using an emulator).

and do this :

mp.setDataSource("/sdcard/audio/temp.wav");
Aswathy P Krishnan

The audio files can be moved to a folder named raw which should be created in the res folder.

It can be accessed by the following code:

MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.soundclip);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.start();

This is the easiest way. You can try it..

hope this will help:

raw/

Arbitrary files to save in their raw form. To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename.

However, if you need access to original file names and file hierarchy, you might consider saving some resources in the assets/ directory (instead of res/raw/). Files in assets/ are not given a resource ID, so you can read them only using AssetManager.

it's from the dev guide.

[Edit: but I do not think that it is a good idea to put your music files into the res directory at all - it depends on what is the purpose of these files?]

james

Note that prepare can take some time, so it may slow the users interactions with your app. See the dev notes here, in particular the section Asynchronous Preparation!

You could also use the SoundPool if the files are less than 1MB in size. This handles synchronization with the UI thread for you. This is a very useful article on the use of it (Lars has a number of great articles!).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!