简单音乐播放器 源码下载

移动开发
学习使用的音乐播放器,登陆密码是123,。

功能分类:影音

支持平台:Android

运行环境:Android

开发语言:Java

开发工具:Eclipse

源码大小:7.88M

源码简介

学习使用的音乐播放器,登陆密码是123,。

源码运行截图

  • 登陆
  • 音乐列表显示
  • 播放界面
  • 收藏界面
 

源码片段

  1. package com.xue.Mp3Player; 
  2.   
  3. import java.util.ArrayList; 
  4. import java.util.HashMap; 
  5. import java.util.List; 
  6.   
  7. import android.app.Activity; 
  8. import android.app.AlertDialog; 
  9. import android.app.AlertDialog.Builder; 
  10. import android.app.ExpandableListActivity; 
  11. import android.content.Context; 
  12. import android.content.DialogInterface; 
  13. import android.content.DialogInterface.OnClickListener; 
  14. import android.os.AsyncTask; 
  15. import android.os.Bundle; 
  16. import android.view.KeyEvent; 
  17. import android.view.LayoutInflater; 
  18. import android.view.View; 
  19. import android.view.ViewGroup; 
  20. import android.widget.BaseExpandableListAdapter; 
  21. import android.widget.ExpandableListView; 
  22. import android.widget.ImageButton; 
  23. import android.widget.TextView; 
  24. import android.widget.Toast; 
  25.   
  26. import com.xue.Mp3Player.R; 
  27. import com.xue.Mp3Player.Utils.DataUtils; 
  28. import com.xue.Mp3Player.Utils.MyApplication; 
  29. import com.xue.Mp3Player.Utils.PlayUtils; 
  30.   
  31. public class MyMusicListActivity extends ExpandableListActivity { 
  32.   
  33.     private ExpandableListView myMusicListView; 
  34.     private ArrayList<hashmap<string, object="">> groupsList; 
  35.     private List<list<hashmap<string, object="">>> childsList; 
  36.     public static MyMusicListAdapter listAdapter; 
  37.     private static Context context; 
  38.   
  39.     @Override 
  40.     protected void onCreate(Bundle savedInstanceState) { 
  41.         super.onCreate(savedInstanceState); 
  42.         setContentView(R.layout.mymusic_list_layout); 
  43.         myMusicListView = getExpandableListView(); 
  44.         context = this
  45.   
  46.         groupsList = new ArrayList<hashmap<string, object="">>(); 
  47.         HashMap<string, object=""> group1 = new HashMap<string, object="">(); 
  48.         group1.put("name""旧城"); 
  49.         HashMap<string, object=""> group2 = new HashMap<string, object="">(); 
  50.         group2.put("name""旧梦"); 
  51.         HashMap<string, object=""> group3 = new HashMap<string, object="">(); 
  52.         group3.put("name""旧人");//设置收藏类别 
  53.         groupsList.add(group1); 
  54.         groupsList.add(group2); 
  55.         groupsList.add(group3); 
  56.   
  57.         childsList = new ArrayList<list<hashmap<string, object="">>>(); 
  58.         childsList.add(MyApplication.getHappyMusicList()); 
  59.         childsList.add(MyApplication.getQuietMusicList()); 
  60.         childsList.add(MyApplication.getSadMusicList()); 
  61.   
  62.         listAdapter = new MyMusicListAdapter(this, groupsList, childsList); 
  63.         myMusicListView.setAdapter(listAdapter); 
  64.     } 
  65.       
  66.     public static Context getContext(){ 
  67.         return context; 
  68.     } 
  69.   
  70.     @Override 
  71.     public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { 
  72.         HashMap<string, object=""> map = childsList.get(groupPosition).get(childPosition); 
  73.         if (map.get("name").equals(PlayService.name) && MyApplication.playStatus == 1) { 
  74.             Toast.makeText(context, "正在播放..."0).show(); 
  75.         }else { 
  76.             boolean b = PlayUtils.addMusicToList(context, map, MyApplication.getPlayMusicList()); 
  77.             if (b) { 
  78.                 PlayMusicListActivity.myListAdapter.notifyDataSetChanged(); 
  79.                 PlayUtils.turnToPlay(map, context); 
  80.             } 
  81.         } 
  82.           
  83.         return super.onChildClick(parent, v, groupPosition, childPosition, id); 
  84.     } 
  85.   
  86.     public boolean onKeyDown(int keyCode, android.view.KeyEvent event) { 
  87.         if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { 
  88.             backDialog(); 
  89.         } 
  90.         return false
  91.     }; 
  92.   
  93.     @Override 
  94.     protected void onDestroy() { 
  95.         DataUtils.upData_allLists(); 
  96.         super.onDestroy(); 
  97.     } 
  98.   
  99.     public void backDialog() { 
  100.         AlertDialog.Builder builder = new Builder(this); 
  101.         builder.setMessage("确认退出吗?"); 
  102.         builder.setTitle("提示"); 
  103.         builder.setPositiveButton("确认"new OnClickListener() { 
  104.   
  105.               
  106.             public void onClick(DialogInterface dialog, int which) { 
  107.                 dialog.dismiss(); 
  108.                 ((Activity) context).finish(); 
  109.                 new AsyncTask<voidvoid,="" void="">(){ 
  110.   
  111.                     @Override 
  112.                     protected Void doInBackground(Void... params) { 
  113.                         if (MyApplication.playStatus != 0) { 
  114.                             PlayService.stop(); 
  115. //                          PlayService.player.release(); 
  116.                         } 
  117.                         DataUtils.upData_allLists(); 
  118.                         return null
  119.                     } 
  120.                       
  121.                 }.execute(); 
  122.             } 
  123.         }); 
  124.         builder.setNegativeButton("取消"new OnClickListener() { 
  125.   
  126.               
  127.             public void onClick(DialogInterface dialog, int which) { 
  128.                 dialog.dismiss(); 
  129.             } 
  130.         }); 
  131.         builder.create().show(); 
  132.     } 
  133.   
  134.     class MyMusicListAdapter extends BaseExpandableListAdapter { 
  135.   
  136.         private Context context; 
  137.         private List<hashmap<string, object="">> groups; 
  138.         private List<list<hashmap<string, object="">>> childs; 
  139.         private childViewsHolder childHolder; 
  140.         private GroupViewsHolder groupHolder; 
  141.   
  142.         public MyMusicListAdapter(Context context, List<hashmap<string, object="">> groups, List<list<hashmap<string, object="">>> childs) { 
  143.             this.context = context; 
  144.             this.groups = groups; 
  145.             this.childs = childs; 
  146.         } 
  147.   
  148.         private class childViewsHolder { 
  149.             TextView childText; 
  150.             ImageButton childButton; 
  151.         } 
  152.   
  153.           
  154.         public Object getChild(int arg0, int arg1) { 
  155.             return childs.get(arg0).get(arg1); 
  156.         } 
  157.   
  158.           
  159.         public long getChildId(int groupPosition, int childPosition) { 
  160.             return childPosition; 
  161.         } 
  162.   
  163.         public void removeChildItem(int groupPosition, int childPosition) { 
  164.             childs.get(groupPosition).remove(childPosition); 
  165.             this.notifyDataSetChanged(); 
  166.         } 
  167.   
  168.           
  169.         public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
  170.             if (convertView != null) { 
  171.                 childHolder = (childViewsHolder) convertView.getTag(); 
  172.             } else { 
  173.                 childHolder = new childViewsHolder(); 
  174.                 LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
  175.                 convertView = inflater.inflate(R.layout.mymusic_childs_layout, null); 
  176.                 childHolder.childText = (TextView) convertView.findViewById(R.id.text_childItem); 
  177.                 childHolder.childButton = (ImageButton) convertView.findViewById(R.id.button_deleteChildItem); 
  178.                 convertView.setTag(childHolder); 
  179.             } 
  180.   
  181.             HashMap<string, object=""> childItem = childs.get(groupPosition).get(childPosition); 
  182.             if (childItem != null) { 
  183.                 String name = (String) childItem.get("name"); 
  184.                 childHolder.childText.setText(name); 
  185.                 childHolder.childButton.setOnClickListener(new childItemOnClick(groupPosition, childPosition)); 
  186.             } 
  187.             return convertView; 
  188.         } 
  189.   
  190.         public class childItemOnClick implements android.view.View.OnClickListener { 
  191.   
  192.             private int groupPosition; 
  193.             private int childPosition; 
  194.   
  195.             public childItemOnClick(int groupPosition, int childposition) { 
  196.                 this.groupPosition = groupPosition; 
  197.                 this.childPosition = childposition; 
  198.             } 
  199.   
  200.           
  201.             public void onClick(View v) { 
  202.                 removeChildItem(groupPosition, childPosition); 
  203.             } 
  204.   
  205.         } 
  206.   
  207.           
  208.         public int getChildrenCount(int groupPosition) { 
  209.             return childs.get(groupPosition).size(); 
  210.         } 
  211.   
  212.           
  213.         public Object getGroup(int groupPosition) { 
  214.             return groups.get(groupPosition); 
  215.   
  216.         } 
  217.   
  218.           
  219.         public int getGroupCount() { 
  220.             return groups.size(); 
  221.         } 
  222.   
  223.           
  224.         public long getGroupId(int groupPosition) { 
  225.             return groupPosition; 
  226.         } 
  227.   
  228.         private class GroupViewsHolder { 
  229.             TextView groupText; 
  230.             ImageButton groupButton; 
  231.         } 
  232.   
  233.       
  234.         public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
  235.             if (convertView != null) { 
  236.                 groupHolder = (GroupViewsHolder) convertView.getTag(); 
  237.             } else { 
  238.                 groupHolder = new GroupViewsHolder(); 
  239.                 LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
  240.                 convertView = inflater.inflate(R.layout.mymusic_groups_layout, null); 
  241.                 groupHolder.groupText = (TextView) convertView.findViewById(R.id.text_groupItem); 
  242.                 groupHolder.groupButton = (ImageButton) convertView.findViewById(R.id.button_playAll); 
  243.                 convertView.setTag(groupHolder); 
  244.             } 
  245.   
  246.             HashMap<string, object=""> map = groups.get(groupPosition); 
  247.             if (map != null) { 
  248.                 String name = (String) map.get("name"); 
  249.                 groupHolder.groupText.setText(name); 
  250.                 groupHolder.groupButton.setOnClickListener(new GroupOnClick(groupPosition)); 
  251.             } 
  252.   
  253.             return convertView; 
  254.         } 
  255.   
  256.         class GroupOnClick implements View.OnClickListener { 
  257.   
  258.             private int position; 
  259.   
  260.             public GroupOnClick(int position) { 
  261.                 this.position = position; 
  262.             } 
  263.   
  264.               
  265.             public void onClick(View v) { 
  266.                 switch (position) { 
  267.                 case 0
  268.                     PlayUtils.turnToPlay_List(context, MyApplication.getHappyMusicList()); 
  269.                     break
  270.                 case 1
  271.                     PlayUtils.turnToPlay_List(context, MyApplication.getQuietMusicList()); 
  272.                     break
  273.                 case 2
  274.                     PlayUtils.turnToPlay_List(context, MyApplication.getSadMusicList()); 
  275.                     break
  276.                 default
  277.                     break
  278.                 } 
  279.             } 
  280.         } 
  281.   
  282.           
  283.         public boolean hasStableIds() { 
  284.             // TODO Auto-generated method stub 
  285.             return false
  286.         } 
  287.   
  288.           
  289.         public boolean isChildSelectable(int groupPosition, int childPosition) { 
  290.             // TODO Auto-generated method stub 
  291.             return true
  292.         } 
  293.   
  294.     } 
  295.   
  296. </string,></string,></list<hashmap<string,></hashmap<string,></list<hashmap<string,></hashmap<string,></void,></string,></list<hashmap<string,></string,></string,></string,></string,></string,></string,></hashmap<string,></list<hashmap<string,></hashmap<string,> 

源码下载地址:http://down.51cto.com/data/1968750

责任编辑:闫佳明 来源: 网络整理
相关推荐

2011-06-27 11:23:21

Qt 音乐播放器

2015-01-22 15:44:55

Android源码音乐播放器

2009-12-17 15:10:31

Linux音乐播放器

2015-01-19 13:52:38

Android源码多功能播放器

2019-02-11 09:20:35

Linux音乐播放器

2011-04-06 10:03:45

谷歌云计算Android音

2017-03-01 14:01:31

android多媒体音乐代码

2017-02-20 09:15:34

Linux播放器Qmmp

2011-08-30 09:48:07

Ubuntu

2021-08-24 15:13:06

鸿蒙HarmonyOS应用

2013-07-23 17:55:14

酷狗音乐mac

2009-06-17 09:56:23

网络音乐播放器

2011-08-30 13:18:43

UbuntuQmmp

2009-08-05 09:48:42

iPod自爆

2012-04-05 13:19:06

WEBHTML5

2022-12-27 18:00:26

Harmonoid音乐播放器

2023-10-30 13:14:57

Moosync开源播放器

2010-06-11 12:49:52

openSUSE播放器

2015-09-01 16:48:44

ios暴风视频播放器

2011-06-13 09:33:04

点赞
收藏

51CTO技术栈公众号