我怎么才能获得特定专辑的歌曲

时间:2018-02-18 10:36:32

标签: android media-queries android-mediaplayer

我想获得特定专辑的歌曲,就像我点击专辑时我应该只获得该专辑的歌曲。我得到所有专辑,当我点击专辑时,我得到设备上的所有歌曲。该专辑中没有。所以请告诉我该怎么做。我尝试了很多stackoverflow的答案,但没有得到答案。

pipeline()

1 个答案:

答案 0 :(得分:0)

i solved by doing this.   

 public  class songAdapter extends RecyclerView.Adapter<songAdapter.SongHolder>{
        private Context context;
        MediaMetadataRetriever metaRetriver;
        byte[] art;
        private OnItemClickListener mOnItemClickListener;
        private ArrayList<songInfo> _songs = new ArrayList<songInfo>();
        public songAdapter(Context context, ArrayList<songInfo> songs) {
            this.context = context;
            this._songs = songs;
        }

        public interface OnItemClickListener {
            void onItemClick(RecyclerView.ViewHolder holder, View view, songInfo obj, int position);

            //void onItemClick(Button b, View view, songInfo obj, int position);
        }

        public void setOnItemClickListener(final OnItemClickListener mItemClickListener) {
            this.mOnItemClickListener = mItemClickListener;
        }


        @Override
        public SongHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
            View myView = LayoutInflater.from(context).inflate(R.layout.card, viewGroup, false);
            return new SongHolder(myView);
        }
        @Override
        public void onBindViewHolder(final SongHolder songHolder, final int i) {
            final songInfo s = _songs.get(i);
            metaRetriver = new MediaMetadataRetriever();
            metaRetriver.setDataSource(_songs.get(i).getId());
            try {
                art = metaRetriver.getEmbeddedPicture();
                Bitmap songImage = BitmapFactory.decodeByteArray(art, 0, art.length);
                songHolder.album_art.setImageBitmap(songImage);
            } catch (Exception e) {
                //  Drawable resId;
                //resId = R.drawable.music;
                songHolder.album_art.setBackgroundResource(R.drawable.music);
            }

            //final String filename = "android.resource://" + this.context + "/raw/test0";
            songHolder.tvSongName.setText(_songs.get(i).getSongName());
            songHolder.tvSongArtist.setText(_songs.get(i).getArtistName());

         added this
      /* 
         songHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(mOnItemClickListener!=null)
                    {
                        mOnItemClickListener.onItemClick(songHolder, view, s, i);
                    }
                }
            });*/
        }



        @Override
        public int getItemCount() {
            return _songs.size();
        }
        public class SongHolder extends RecyclerView.ViewHolder {
            TextView tvSongName,tvSongArtist;
            ImageView album_art;
            SeekBar seekBar;
            public SongHolder(View itemView) {
                super(itemView);
                tvSongName = itemView.findViewById(R.id.songName);
                tvSongArtist =  itemView.findViewById(R.id.artistName);
                album_art =  itemView.findViewById(R.id.albumArt);
                seekBar=(SeekBar)itemView.findViewById(R.id.seekBar);
            }
        }
        public void setSearchResult(List<songInfo> result) {
            _songs = (ArrayList<songInfo>) result;
            notifyDataSetChanged();
        }
    }