@Override protected void onListItemClick(ListView l, View v, int position, long id) { if (getListAdapter() == mHistoryAdapter) { String selection = ((TextView) v.findViewById(android.R.id.text1)).getText().toString(); mSearchText.setText(selection); mSearchText.setSelection(selection.length()); mSearchText.requestFocus(); } else if (getListAdapter() == mResultAdapter) { // add search text to the database (history) MediaDatabase db = MediaDatabase.getInstance(this); db.addSearchhistoryItem(mSearchText.getText().toString()); // open media in the player Media item = (Media) getListAdapter().getItem(position - 1); if (item.getType() == Media.TYPE_VIDEO) { VideoPlayerActivity.start(this, item.getLocation()); } else { ArrayList<String> arr = new ArrayList<String>(); for (int i = 0; i < getListAdapter().getCount(); i++) { Media audioItem = (Media) getListAdapter().getItem(i); if (audioItem.getType() == Media.TYPE_AUDIO) arr.add(audioItem.getLocation()); } AudioServiceController.getInstance().load(arr, arr.indexOf(item.getLocation())); AudioPlayerActivity.start(this); } super.onListItemClick(l, v, position, id); } };
public static void openMedia(final Context context, final MediaWrapper media) { if (media == null) return; if (media.getType() == MediaWrapper.TYPE_VIDEO) VideoPlayerActivity.start(context, media.getUri(), media.getTitle()); else if (media.getType() == MediaWrapper.TYPE_AUDIO) { new DialogCallback( context, new DialogCallback.Runnable() { @Override public void run(PlaybackService service) { service.load(media); } }); } }