Error preparing MediaPlayer

Error preparing MediaPlayer



My application consists of uploading a single media file from the users SDcard and uploading it to a listview. That part it self, works perfectly. Each uri is saved under an SQlite database which saves the files in the listview as well.



However, Now I am trying to obtain its path and URI on itemClick so I am able to Start playing any audio file I want.



The issue is that the URI is getting an error when I start to prepare it. I'm not sure if I formatted everything correctly, as I receive this error:


08-18 13:11:12.790 24401-25067/com.example.daniel.queue E/MediaPlayerNative: error (1, -2147483648)



I understand this error could mean a few things, but please, let me know if I am formatting my URI or path correctly. I have my permissions so that is not the issue. I assume it may be a formatting issue but I am yet to find a solution.


private void ItemClick()

user_music_reccomadatons.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l)
String pos = adapterView.getItemAtPosition(position).toString();
Uri uriFile = Uri.fromFile(new File(pos)); //creates a Uri from a file
String pathFile = uriFile.getEncodedPath(); //gets coded path
String path = Environment.getExternalStorageState() + pathFile;
MediaPlayer mp = new MediaPlayer();
try
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDataSource(getApplicationContext(), uriFile);
Log.d("DATA SOURCE"," GOT DATA SOURCE " + path);

catch (IOException e)
Log.d("ERROR", "ERROR ON SETDATASOURCE");

try
mp.prepare();
Log.d("Success!","");
catch (IOException e)
Log.d("error", " ERROR PREPARING");




Log.d("data", "URI: "+ uriFile + " PATH "+ pathFile);
Log.d("ENVI PATH", " path: "+ path);






);





Are you sure your setDataSource is not returning any error?
– kiran Biradar
Aug 8 at 19:58





Not that Ive seen in the logcat.. the main error line seems to be what I posted
– Daniel Palacios
Aug 8 at 20:14





How am I able to find the path for any uri file that I click on the list view thats on my sdcard?
– Daniel Palacios
Aug 8 at 20:15





I feel like that could be a possible solution but Im not sure how to implement it...
– Daniel Palacios
Aug 8 at 20:15





Just hardcode the one file path for testing
– kiran Biradar
Aug 8 at 20:22









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Help:Category

How can temperature be calculated given relative humidity and dew point?

I have a recursive function to validate tree graph and need a return condition