Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Intents to play audio files
    text
    copied!<p>I am trying to create a media player that only plays .mp3 files. I have the list created and showing on my app but I cant get it to play the song. I was advised to use an intent but I dont know how to do it.</p> <p>Here is the code;</p> <pre><code>ListView list; Cursor cursor; int columnIndex; int count; private ArrayAdapter arrayAdapter; private Button dropbox; public MainActivity() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); dropbox = (Button) findViewById(R.id.dropbox); list = (ListView) findViewById(android.R.id.list); dropbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.dropbox.com")); startActivity(i); } }); String[] displayMusic = {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DISPLAY_NAME}; cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, displayMusic, null, null, null); //0 is the id for a mp3 file on the sd card //1 is the file name of the mp3 file on the sd card final ArrayList&lt;String&gt; listOfMp3s = new ArrayList&lt;String&gt;(); final ArrayList&lt;String&gt; listOfIds = new ArrayList&lt;String&gt;(); while (cursor.moveToNext()) { if(cursor.getString(1).endsWith("mp3")) { listOfMp3s.add(cursor.getString(1)); listOfIds.add(cursor.getString(0)); } } arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, listOfMp3s); list.setAdapter(arrayAdapter); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { Intent songPageIntent = new Intent(getApplicationContext(), SongPage.class); startActivity(songPageIntent); } }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload