Question

i am developing an application of Call recording . it record the call and save it in Phone memory(file Manager) and after saving audio file, i managed to show the recorded file in list View. know when i Click the file on List to play it gives the prepares failed error. I am posting the code.

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    listView = (ListView) findViewById(R.id.mylist);
            mp = new MediaPlayer();
    // this will show the recorded files into ListVIew
    myList = new ArrayList<String>();
    files = new File(Environment.getExternalStorageDirectory()
            + "/Audio File/");
    File list[] = files.listFiles();
    for (int i = 0; i < list.length; i++) {
        myList.add(list[i].getName());
    }

    adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, myList);
    listView.setAdapter(adapter);

    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            try {
                playSong(files + myList.get(position));
            } catch (Exception e) {
                Log.d("PlaySong", "Error in Playing song "+e.toString());
            }

            // just for checking the position of item in list
            Object listItem = listView.getItemAtPosition(position);
            Toast.makeText(MainActivity.this, "" + listItem,
                    Toast.LENGTH_SHORT).show();
        }

        private void playSong(String string) throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {

            mp.reset();
            mp.setDataSource(string);
            mp.prepare();
            mp.start();
        }

    });
}

the error is

  03-07 14:40:25.866: I/SurfaceTextureClient(15355): [STC::queueBuffer] this:0x4f11d050,             api:1, last queue time elapsed :11282 ms
  03-07 14:40:25.866: I/SurfaceTextureClient(15355): [0x4f11d050] frames:2, duration:11.356000, fps:0.176113
  03-07 14:40:25.916: V/Provider/Setting(15355): from settings cache , name = sound_effects_enabled value = 0
  03-07 14:40:25.918: D/MediaPlayer(15355): mPlayerID = 48
  03-07 14:40:25.927: E/MediaPlayer(15355): error (1, -2147483648)
  03-07 14:40:25.927: D/PlaySong(15355): Error in Playing song java.io.IOException: Prepare failed.: status=0x1
Was it helpful?

Solution

I only suggest you to write this code in your previous question, so might be below is the main issue that is causing problem.

Try to declare your

files = new File(Environment.getExternalStorageDirectory()+ "/Audio File/");

as a

private static final String files = new String(
            Environment.getExternalStorageDirectory() + "/Audio File/");

You have declare a path as a File, so change it with a String and then try.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top