title: Android playing the audio file in a listview
body: <p>I have a listview that show all files in the folder <code>/diarioscolastico</code></p>
  
  <p>This is my code</p>
  
  <pre><code>public class ActivityRegistrazione extends ActionBarActivity {
  
      private static final String LOG_TAG = "AudioRecordTest";
      private static String mFileName = null;
      private MediaRecorder mRecorder = null;
      private MediaPlayer   mPlayer = null;
  
      //Used for audio listview
      private List&lt;String&gt; myList;
      File file;
      ArrayAdapter&lt;String&gt; adapter;
  
      //Variabile usata per usare un solo bottone come start/stop
      boolean mStartRecording = true;
  
      private void onRecord(boolean start) {
          if (start) {
  
              //Creo un file per ogni registrazione che viene fatta partire
              File mFolder = new File(Environment.getExternalStorageDirectory() + "/diarioscolastico");
              mFileName = Environment.getExternalStorageDirectory() + "/diarioscolastico";
  
  
              boolean success = true;
              if (!mFolder.exists()) {
                  success = mFolder.mkdir();
              }
              if (success) {
  
                  // Create an audio file name
                  String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
                  String audioFileName = "AUDIO_" + timeStamp + "_.3gp";
                  // Do something on success
                  mFileName += "/"+ audioFileName ;
  
              } else {
                  // Do something else on failure
              }
  
              startRecording();
  
          } else {
              stopRecording();
  
              //Aggiorno la listview con la nuova immagine
              //Lista con il nuovo elemento
              List&lt;String&gt; myNewList = new ArrayList&lt;&gt;();
              File directory = Environment.getExternalStorageDirectory();
              file = new File( directory + "/diarioscolastico" );
              File list[] = file.listFiles();
  
              for( int i=0; i&lt; list.length; i++)
              {
                  myNewList.add(0,list[i].getName());
              }
                  //Aggiorno la Listview dell'activity con il nuovo inserimento
                  myList.clear();
                  myList.addAll(myNewList);
                  adapter.notifyDataSetChanged();
          }
      }
  
      private void startRecording() {
          mRecorder = new MediaRecorder();
          mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
          mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
          mRecorder.setOutputFile(mFileName);
          mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  
          try {
              mRecorder.prepare();
          } catch (IOException e) {
              Log.e(LOG_TAG, "prepare() failed");
          }
  
          mRecorder.start();
      }
  
      private void stopRecording() {
          mRecorder.stop();
          mRecorder.release();
          mRecorder = null;
      }
  
      @Override
      public void onCreate(Bundle icicle) {
          super.onCreate(icicle);
  
          setContentView(R.layout.activity_registrazione);
  
          final Button recButton = (Button) findViewById(R.id.recButton);
          recButton.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  // Perform action on click
  
                 onRecord(mStartRecording);
                  if (mStartRecording) {
                      recButton.setText("Stop");
                  } else {
                      recButton.setText("Rec");
                  }
                  mStartRecording = !mStartRecording;
              }
          });
  
          ListView audioListView = (ListView) findViewById(R.id.audioList);
          myList = new ArrayList&lt;&gt;();
  
          adapter = new ArrayAdapter&lt;&gt;(this,
                  android.R.layout.simple_list_item_1, android.R.id.text1, myList);
  
          File directory = Environment.getExternalStorageDirectory();
          file = new File( directory + "/diarioscolastico" );
          File list[] = file.listFiles();
  
          for( int i=0; i&lt; list.length; i++)
          {
              myList.add(0, list[i].getName());
          }
  
          audioListView.setAdapter(adapter); //Set all the file in the list.
  
          // ListView Item Click Listener
          audioListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
                  //TODO play the touched audio file in listview
  
  
              }
          });
  
      }
  
      @Override
      public void onPause() {
          super.onPause();
          if (mRecorder != null) {
              mRecorder.release();
              mRecorder = null;
          }
  
          if (mPlayer != null) {
              mPlayer.release();
              mPlayer = null;
          }
      }
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_activity_registrazione, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  }
  </code></pre>
  
  <p>My problem is that when i click an audio file in the listview i don't know how start some media player for listen the audio.
  I found some hold stackoverflow post but they are posted in the 2010.</p>
  
  <p>I found this code too:</p>
  
  <pre><code>Uri myUri = ....; // initialize Uri here
  MediaPlayer mediaPlayer = new MediaPlayer();
  mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  mediaPlayer.setDataSource(getApplicationContext(), myUri);
  mediaPlayer.prepare();
  mediaPlayer.start();
  </code></pre>
  
  <p>But how can i take the uri from the listview audio file name?</p>
  
  <p>There are some better ways to do this?
  Can i use some intents for use the standard audioplayer?</p>