Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>**Check with the following class it will list out all th songs in the device also it play the song when click on that name.** public class NewMp3PlayerActivity extends Activity { ListView musiclist; int music_column_index,music_column_index1; int count; MediaPlayer mMediaPlayer; ImageView play, pause, forward, backward; int pposition; ArrayList&lt;String&gt; songs = new ArrayList&lt;String&gt;(); String songName; Cursor musiccursor; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.songpreview); play = (ImageView)findViewById(R.id.img_play); pause = (ImageView)findViewById(R.id.img_pause); forward = (ImageView)findViewById(R.id.img_forward); backward = (ImageView)findViewById(R.id.img_backward); play.setOnClickListener(OnClick); pause.setOnClickListener(OnClick); forward.setOnClickListener(OnClick); backward.setOnClickListener(OnClick); init_phone_music_grid(); } View.OnClickListener OnClick = new View.OnClickListener() { @Override public void onClick(View v) { music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA); Log.e("", "musiccursor.getCount()--&gt;"musiccursor.getCount()); switch(v.getId()){ case R.id.img_play: Log.v("", "list of songs--&gt;"+songs); if (mMediaPlayer.isPlaying()) { mMediaPlayer.reset(); } mMediaPlayer.start(); break; case R.id.img_pause: if (mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); } break; case R.id.img_forward: // musiccursor.moveToPosition(pposition+1); try { String filename=""; if (pposition &lt; songs.size()){ pposition = pposition+1; filename = songs.get(pposition);//musiccursor.getString(music_column_index); }else{ } Log.e("", "filename--&gt;"+filename); mMediaPlayer.reset(); mMediaPlayer.setDataSource(filename); mMediaPlayer.prepare(); mMediaPlayer.start(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch(IndexOutOfBoundsException ie){ pposition = 0; } break; case R.id.img_backward: try { String filename_n=""; if (pposition &lt;= songs.size()){ pposition = pposition-1; filename_n = songs.get(pposition);//musiccursor.getString(music_column_index); }else{ } mMediaPlayer.reset(); mMediaPlayer.setDataSource(filename_n); mMediaPlayer.prepare(); mMediaPlayer.start(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch(ArrayIndexOutOfBoundsException ar){ pposition = songs.size(); } break; default: break; } } }; private void init_phone_music_grid() { System.gc(); String[] proj = { MediaStore.Audio.Media._ID,MediaStore.Audio.Media.DATA,MediaStore.Audio.Media.DISPLAY_NAME,MediaStore.Video.Media.SIZE }; musiccursor = managedQuery(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, proj, null, null, null); Log.e("", "filename--&gt;"musiccursor.getCount()); count = musiccursor.getCount(); musiclist = (ListView) findViewById(R.id.lst_music); musiclist.setAdapter(new MusicAdapter(getApplicationContext())); musiclist.setOnItemClickListener(musicgridlistener); mMediaPlayer = new MediaPlayer(); mMediaPlayer.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { try { String filename=""; if (pposition &lt; songs.size()){ pposition = pposition+1; filename = songs.get(pposition);//musiccursor.getString(music_column_index); }else{ } Log.e("", "filename--&gt;"+filename); mMediaPlayer.reset(); mMediaPlayer.setDataSource(filename); mMediaPlayer.prepare(); mMediaPlayer.start(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch(IndexOutOfBoundsException ie){ pposition = 0; } } }); } private OnItemClickListener musicgridlistener = new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position,long id) { System.gc(); pposition = position; music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA); musiccursor.moveToPosition(position); String filename = musiccursor.getString(music_column_index); String filen = songs.get(pposition); Log.e("", "index--&gt;"+music_column_index); try { mMediaPlayer.reset(); mMediaPlayer.setDataSource(filen); mMediaPlayer.prepare(); // mMediaPlayer.start(); } catch (Exception e) { } } }; public class MusicAdapter extends BaseAdapter { private Context mContext; public MusicAdapter(Context c) { mContext = c; } public int getCount() { return count; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { System.gc(); TextView tv = new TextView(mContext.getApplicationContext()); String id = null; if (convertView == null) { music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME); music_column_index1 = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA); musiccursor.moveToPosition(position); id = musiccursor.getString(music_column_index); songName = musiccursor.getString(music_column_index); songs.add( musiccursor.getString(music_column_index1) ); music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE); musiccursor.moveToPosition(position); id += " Size(KB):" + musiccursor.getString(music_column_index); tv.setText(id); } else tv = (TextView) convertView; return tv; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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