@Override
  public boolean onContextItemSelected(MenuItem item) {
    if (!getUserVisibleHint()) return super.onContextItemSelected(item);

    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    if (menuInfo == null) // getMenuInfo can be NULL
    return super.onContextItemSelected(item);

    int startPosition;
    List<String> medias;
    int id = item.getItemId();

    boolean useAllItems =
        (id == R.id.audio_list_browser_play_all || id == R.id.audio_list_browser_append_all);
    boolean append =
        (id == R.id.audio_list_browser_append || id == R.id.audio_list_browser_append_all);

    if (id == R.id.audio_list_browser_delete) {
      final Media media = mSongsAdapter.getItem(menuInfo.position);
      AlertDialog dialog =
          CommonDialogs.deleteMedia(
              getActivity(),
              media.getLocation(),
              new VlcRunnable(media) {
                @Override
                public void run(Object o) {
                  mMediaLibrary.getMediaItems().remove(media);
                  updateList();
                }
              });
      dialog.show();
      return true;
    }

    if (id == R.id.audio_list_browser_set_song) {
      AudioUtil.setRingtone(mSongsAdapter.getItem(menuInfo.position), getActivity());
      return true;
    }

    if (useAllItems) {
      startPosition = menuInfo.position;
      medias = mSongsAdapter.getLocations();
    } else {
      startPosition = 0;
      medias = mSongsAdapter.getLocation(menuInfo.position);
    }
    if (append) mAudioController.append(medias);
    else {
      mAudioController.load(medias, startPosition);
      AudioPlayerFragment.start(getActivity());
    }

    return super.onContextItemSelected(item);
  }
  private boolean handleContextItemSelected(MenuItem item, int position) {
    ContextMenuInfo menuInfo = item.getMenuInfo();

    int startPosition;
    int groupPosition;
    List<String> medias;
    int id = item.getItemId();

    boolean useAllItems = id == R.id.audio_list_browser_play_all;
    boolean append = id == R.id.audio_list_browser_append;

    if (ExpandableListContextMenuInfo.class.isInstance(menuInfo)) {
      ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
      groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
    } else groupPosition = position;

    if (id == R.id.audio_list_browser_delete) {
      AlertDialog alertDialog =
          CommonDialogs.deleteMedia(
              getActivity(),
              mSongsAdapter.getLocations(groupPosition).get(0),
              new VlcRunnable(mSongsAdapter.getItem(groupPosition)) {
                @Override
                public void run(Object o) {
                  AudioBrowserListAdapter.ListItem listItem = (AudioBrowserListAdapter.ListItem) o;
                  Media media = listItem.mMediaList.get(0);
                  mMediaLibrary.getMediaItems().remove(media);
                  mSongsAdapter.removeMedia(media);
                  mAlbumsAdapter.removeMedia(media);
                  mAudioController.removeLocation(media.getLocation());
                }
              });
      alertDialog.show();
      return true;
    }

    if (id == R.id.audio_list_browser_set_song) {
      AudioUtil.setRingtone(mSongsAdapter.getItem(groupPosition).mMediaList.get(0), getActivity());
      return true;
    }

    if (useAllItems) {
      medias = new ArrayList<String>();
      startPosition = mSongsAdapter.getListWithPosition(medias, groupPosition);
    } else {
      startPosition = 0;
      switch (mTabHost.getCurrentTab()) {
        case 0: // albums
          medias = mAlbumsAdapter.getLocations(groupPosition);
          break;
        case 1: // songs
          medias = mSongsAdapter.getLocations(groupPosition);
          break;
        default:
          return true;
      }
    }

    if (append) mAudioController.append(medias);
    else mAudioController.load(medias, startPosition);

    return super.onContextItemSelected(item);
  }