zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    RHEL安装oracle客户端(版本为11.2)
    为服务器设置固定IP地址
    RHEL配置本地yum
    网线水晶头内线排序
    《汇编语言(第三版)》王爽著----读书笔记01
    kali系统越来越大解决
    Markdown入门简介
    Linux之tail命令
    Linux之df命令
    Linux命令
  • 原文地址:https://www.cnblogs.com/ronzzj/p/10104971.html
Copyright © 2011-2022 走看看