This is the previous post.
About mp3 player
And the picture below is my A.mp3 path I find in my phone.
`
mediaPlayer.setDataSource("/storage/sdcard1/A.mp3")
File file =new File(Environment.getExternalStorageDirectory(),"A.mp3");
mediaPlayer.setDataSource(file.getPath());
There are two paths above..According the picture,it should be the first one,but it does not work.
I push A.mp3 into the internal storage,and play is ok.
mediaPlayer.setDataSource("/system/A.mp3");
I finally find that the two files got different permission.I don't know what do those "wrdrrwrwrwrw*****" mean.So I need to search it .
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
This permission was forgotten.Now is ok
Firstly- Check that the SD card is mounted and readable.
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED));
or
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY));
From your question here: You are using:
File file =new File(Environment.getExternalStorageDirectory(),"A.mp3");
mediaPlayer.setDataSource(file.getPath());
and have tried:
mediaPlayer.setDataSource("/storage/sdcard1/A.mp3")
Then try:
Edit: add in Music folder.
mediaPlayer.setDataSource("/sdcard1/Music/A.mp3");
Also: this http://www.bogotobogo.com/Android/android24Media.php#SDCard is an interesting link. So you can explore you files in Android Studio.
Related
I am trying to read local pdf file which is saved in Android download folder.
I created app and set everything like it should be and app reads pdf if it is saved in asset:
Control.LoadUrl(string.Format("file:///android_asset/pdfjs/web/viewer.html?file={0}", string.Format("file:///android_asset/abc.pdf")));
But if I use:
Control.LoadUrl(string.Format("file:///android_asset/pdfjs/web/viewer.html?file={0}", string.Format("file:///storage/emulated/0/Download/foo.pdf")));
nothing is showing.
I checked if file exist:
string abc;
if (File.Exists(string.Format("/storage/emulated/0/Download/foo.pdf")))
{
abc = "exist!!!!";
}
else
{
abc = "not exist!";
}
and it confirmes file exist.
If i use OpenPdf project: https://github.com/acaliaro/OpenPdf
then it can open file saved in Download folder.
What am I doing wrong? Different Android version? Api level? I compared OpenPdf project with my project, everything seems to be ok.
Permisions are set too:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
For everybody who has similar issue:
Solution is very trivial.
Apart from permissions adjusted in AndroidManifest.xml I had to go to phone aplications settings and turn on memory permission manualy.
Everything is working now.
I have an MP3 in my sdcard and I need to use its path for my setdatasource command. I have tried mp.setDataSource("/mnt/media_rw/sdcard/mymusic/thebomb.mp3"); along with many variations but it still won't work. And I don't think it has to do with the rest of the code.
How would I accomplish this?
I guess you are using Emulator.So the path of the SDCard can be get through Environment.getExternalStorageDirectory().Moreover your sdcard must contain that file.So you have to push your file in the SD card.
Use this way:
Uri uri = Uri.parse(Environment.getExternalStorageDirectory()+"/mymusic/thebomb.mp3");
musicPlayer.setDataSource(uri);
Add permission to your manifest.xml file.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
try this like...Simple mediaplayer play mp3 from file path?.
Hope so it will help you.
mpintro = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/intro.mp3"));
mpintro.setLooping(true);
mpintro.start();
Use the below code:
musicPlayer.setDataSource("/sdcard/mymusic/thebomb.mp3");
Try with this -
mp.setDataSource(Environment.getExternalStorageDirectory()+"/mymusic/thebomb.mp3");
Try the following code and is working:
mp.setDataSource("/sdcard/mymusic/thebomb.mp3");
Alright so I created 2 folders in the SD card using the following code:
String folderPath = Environment.getExternalStorageDirectory() + "/AllAroundMe/Images/";
File file = new File(folderPath);
if(!file.exists())
{
if(file.mkdirs());
Log.d("MyTag","Successfully created folders");
}
I tested this program and it really works, the logcat prints the success message above.
But if I navigate to my sd card I don't see "AllAroundMe" folder.
How can I access that folder from my computer?
Try this
Open DDMS perspective -> File Explorer - > mnt -> sdcard
Go to Android DDMS FIleExplorer-->mnt-->sdcard--> and search for your sdcard folder which is created by you
Just check u can`t give the permission in manifest file in your Application just add the permission of this.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Than run your own code the folder has been create in sdcard ok check this.
First i hope you have given the External Storage permission in your Manifest.xml
Do something like this... i know what you did right, but still i prefer this approach.
File f = new File("/sdcard/AllAroundMe/Images/");
Now browse your sdcard from you pc, i am sure you will find the folder.
I want to read text file, that was written by other my app. It's saved ad "Android/data/MyPackageName/files/"
I use this code:
File file = new File("//Android//data//MyPackageName//files//", "filename.txt");
FileInputStream is = new FileInputStream(file);
but i get exception "no such file or directory"
I am sure that solution is pretty simple, but i can't find it yet.
Thank you for your help!
I don't think it is right to use the double backslash "//", one is enough. Also, the path should be "/mnt/sdcard/Android/data....". I am not sure the "/mnt/sdcard" is applicable on every device, so my suggestion is to use Environment.getExternalStorageDirectory to get the root dir on sd card.
I have an xml in /data//files/file.xml and another txt file in same location. I am not able to read those files. It throws me error "The application <...> has stopped unexceptedly" with "Force Close" button and the application quits.
Can anyone help me know the cause of it ? I am really stuck up.
You cant access Ur data file like that.
follow these steps
Create a folder in res folder with name as raw . and save your XML file in raw folder.
then use
InputStream inp = Context.getResources().openRawResource(R.raw.datafile);
u will get InputStream reference. where u can proceed further with it as u need.
Thanks Friends,
I found a solution and now could read the file stored in files folder.
Thanks a lot for your help and support.