Android第三次作业

 

1、 项目

制作一个音乐播放器

2、 实现的功能

1. 实现播放,暂停,停止,播放上一首,下一首功能

2.显示播放列表

3. 至少可以播放3首歌曲

3、截屏

 

4、代码分析

播放事件代码:

 case R.id.play: {
                    if (player.isPlaying()) {
                        handler.removeCallbacks(updatePositionRunnable);
                        player.pause();
                        playButton.setImageResource(R.drawable.pause);
                    } else {
                        if (isStarted) {
                            player.start();
                            playButton.setImageResource(R.drawable.play);
                            updatePosition();
                        } else {
                            startPlay(currentFile);
                        }
                    }
                    break;
                }

音乐资源获取:

    private class MediaCursorAdapter extends SimpleCursorAdapter{

        public MediaCursorAdapter(Context context, int layout, Cursor c){
            super(context, layout,c,
                    new String[] {MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.TITLE, MediaStore.Audio.AudioColumns.DURATION},
                    new int[] {R.id.displayname, R.id.title,R.id.duration});
        }

        @Override
        public void bindView(View view,Context context, Cursor cursor) {
            TextView title = (TextView) view.findViewById(R.id.title);
            TextView name = (TextView) view.findViewById(R.id.displayname);
            TextView duration = (TextView) view.findViewById(R.id.duration);

            name.setText(cursor.getString(
                    cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)));
            name.setTextColor(Color.parseColor("#FFFFFF"));
            title.setText(cursor.getString(
                    cursor.getColumnIndex(MediaStore.MediaColumns.TITLE)));

            long durationInMs = Long.parseLong(cursor.getString(
                    cursor.getColumnIndex(MediaStore.Audio.AudioColumns.DURATION)));
            view.setTag(cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA)));
        }
        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            LayoutInflater inflater = LayoutInflater.from(context);
            View v = inflater.inflate(R.layout.listitem, parent, false);

            bindView(v, context, cursor);

            return v;
        }

 

5、代码链接

https://github.com/ronzzj/1600802138.git

6apk链接

https://raw.githubusercontent.com/ronzzj/1600802138/master/app-debug.apk

 

posted @ 2018-12-11 22:13  TibetRON  阅读(160)  评论(0编辑  收藏  举报