取流派名称列表,其中有歌曲在里面 [英] Fetch Genre name list which have songs in it

查看:133
本文介绍了取流派名称列表,其中有歌曲在里面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我取出由机器人使用CursorLoder类的媒体内容提供商类型列表。
下面是我的光标查询来获取类型的列表中。

I am fetching Genre list from media content Provider of android using CursorLoder class. below is my cursor query to fetch the list of Genre.

 public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        // currently filtering.
        Uri baseUri;
        baseUri = MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI;
        String[] STAR = { "*" };
        return new CursorLoader(getActivity(), baseUri, STAR, null, null, null );
    }

现在,我从媒体内容提供商但是我得到的数据问题的所有流派列表。我也得到了它之前创建的,但现在我没有歌曲吧。音乐流派的名称

Now, i got all the genre list from the media content provider but the problem with the data i got. I also got the genre name which is created before but right now i don't have song in it.

我只希望有歌曲在它的风格,而不是不流派名称中的歌曲在里面。

I only want the genre that have songs in it, not the genre name that dont have songs in it.

谁能帮我呢?

更新

我也能够用低于code,以获取所有类型和它的歌...

I can able to fetch all the Genre and its Song using below code...

private void getGenresList() {

        //-------------------------------------

        int index;
        long genreId;
        int count;
        Uri uri;
        Cursor genrecursor;
        Cursor tempcursor;
        String[] proj1 = {MediaStore.Audio.Genres.NAME, MediaStore.Audio.Genres._ID};   
        String[] proj2={MediaStore.Audio.Media.DISPLAY_NAME};

         genrecursor=getActivity().getContentResolver().query(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI,proj1,null, null, null);
         if(genrecursor.moveToFirst())
         {
             do{
                index = genrecursor.getColumnIndexOrThrow(MediaStore.Audio.Genres.NAME);            
                System.out.println("GENRE NAME: "+genrecursor.getString(index));
                System.out.println("======================================");

                index = genrecursor.getColumnIndexOrThrow(MediaStore.Audio.Genres._ID);             
                genreId=Long.parseLong(genrecursor.getString(index));
                uri = MediaStore.Audio.Genres.Members.getContentUri("external", genreId);

                tempcursor = getActivity().getContentResolver().query(uri, proj2, null,null,null);
                System.out.println("Total Songs: "+tempcursor.getCount());
                if(tempcursor.moveToFirst())
                {
                    do{
                        index=tempcursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME);
                        System.out.println("    Song Name: "+tempcursor.getString(index));

                    }while(tempcursor.moveToNext());
                }
                System.out.println("======================================");
             }while(genrecursor.moveToNext());       
         }


        //-------------------------------------

    }

但是,我必须使用两个查询,一个用于读取所有的流派和第二与流派有哪些歌曲过滤器的数据。即使我想用,在Cu​​rsorLoader所以我如何做到这一点又一个的奇迹。

But, i must have to use two query, one for fetching all the genre and second for filter data with the Genre which have songs. Even i would like to use that in the CursorLoader so i am wonder wonder about how to do that.

希望你得到了什么,我想这个问题正确的想法。

Hope you got proper idea what i want with this question.

推荐答案

好像没有其他的方法来实现这一目标,所以我刚才做象下面...
下面更新我能抽到类型列表,其中只有歌曲吧。被过滤掉不具备的歌曲风格列表。

It seems like there is no other method to achieve this so i have just do like below... With below update i can able to get the Genre list which only have songs in it. The genre list which don't have songs are filtered out.

public Loader<Cursor> onCreateLoader(int id, Bundle args) {

        Uri baseUri;
        if (mCurFilter != null) {
            baseUri = Uri.withAppendedPath(
                    MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                    Uri.encode(mCurFilter));
        } else {
            baseUri = MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI;
        }

        String[] STAR = { MediaStore.Audio.Genres._ID,
                MediaStore.Audio.Genres.NAME };


        String query = " _id in (select genre_id from audio_genres_map where audio_id in (select _id from audio_meta where is_music != 0))" ;

        return new CursorLoader(getActivity(),
                MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, STAR, query,
                null, null);

    }

在上面code,我有加盟种类表音频表。用这种方式,我能够获取,该流派是否具有歌曲与否。所以,现在我只有该流派具有的歌曲吧。

In above code i have join the genre table with audio table. with this way i am able to fetch, whether that Genre have songs or not. So now i have only that genre which have songs in it.

希望这将帮助其他人也。

Hope this will help others also.

享受编码...:)

这篇关于取流派名称列表,其中有歌曲在里面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆