如何创建一个播放列表 [英] How to Create a Playlist

查看:203
本文介绍了如何创建一个播放列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个应用程序,它只是提供了一个EditText和ImageButton的。如果比唐被点击,这个想法是,专辑添加到播放列表,在盒子的EditText命名。专辑应随机选择。不用说,专辑曲目应该是在正确的顺序。 我可以添加更多的功能,例如以后。保存,覆盖,删除等。 我有界面,但我挣扎了code。我有点弄ContentProviders的概念。 因此code需要:

I am trying to create an app which simply offers an edittext and imagebutton. If the butten gets clicked, the idea is that an album is added to the Playlist, named in the edittext box. Albums should be selected randomly. Goes without saying that the album tracks should be in the correct order. I can add more functionality later eg. save, overwrite, delete etc. I have the interface but am struggling with the code. I sort of get the concept of ContentProviders. so the code needs to:

  • 进入播放列表,我相信这是通过使用MediaStore.Audio.Playlists实现

  • access the Playlists, which I believe is achieved by using MediaStore.Audio.Playlists

进入该相册,我相信这是通过使用MediaStore.Audio.Albums实现

access the Albums, which I believe is achieved by using MediaStore.Audio.Albums

添加到播放列表

我有以下的code(从该网站获得最位。感谢BTW)来访问播放列表,但它崩溃使用空异常错误。

I have the following code (most bits obtained from this site. Thanks btw) to access the Playlist but it crashes with a Null Exception error.

public void checkforplaylists()
{
    //Get a cursor over all playlists.
    final ContentResolver resolver= MediaProvider.mContentResolver;
    final Uri uri=MediaStore.Audio.Playlists.INTERNAL_CONTENT_URI;
    final String id=MediaStore.Audio.Playlists._ID;
    final String name=MediaStore.Audio.Playlists.NAME;
    final String[]columns={id,name};
    final Cursor playlists= resolver.query(uri, columns, null, null, null);

        if(playlists==null)
            {
                Log.e(TAG,"Found no playlists.");
                    return;
            }
    return;
}

任何人谁可以帮助?

Anyone who can help?

推荐答案

我想你的意思 NullPointerException异常,这意味着你的任务之一为空,然后您尝试访问对象中的一员,你想要它是。最有可能的是解析,但可以肯定,你需要报告的行号和/或步通过调试器。

I think you mean NullPointerException, which means one of your assignments is null and then you try to access a member of the object you intended it to be. Most likely it is resolver, but to be sure you need the line number reported and/or to step through that with a debugger.

这篇关于如何创建一个播放列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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