版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、46基于android系统的音乐播放器设计与实现基于android系统的音乐播放器设计与实现源程序.projectspmusicplayer01com.android.ide.eclipse.adt.resourcemanagerbuildercom.android.ide.eclipse.adt.precompilerbuilderorg.eclipse.jdt.core.javabuildercom.android.ide.eclipse.adt.apkbuildercom.android.ide.eclipse.adt.androidnatureorg.eclipse.jdt.core.
2、javanature.classpathandroidmanifest.xml localmpslist.javapackage sled.develop;import java.util.arraylist;import java.util.list;import sled.develop.service.listsrv;import sled.model.mpsiterm;import sled.utils.adapterutils;import sled.utils.appconstant;import sled.utils.fileutils;import android.app.li
3、stactivity;import android.content.intent;import android.os.bundle;import android.view.view;import android.view.window;import android.widget.listview;import android.widget.radiobutton;import android.widget.radiogroup;import android.widget.radiogroup.oncheckedchangelistener;import android.widget.simpl
4、eadapter;public class localmpslist extends listactivityprivate list mp3s =null;private radiogroup radiogroup ; private radiobutton single ;private radiobutton order ;private radiobutton radom ;private int mode = appconstant.jump_mode_order ;overrideprotected void oncreate(bundle savedinstancestate)
5、/ todo auto-generated method stubsuper.oncreate(savedinstancestate);requestwindowfeature(window.feature_no_title);setcontentview(r.layout.locallist);single = (radiobutton)findviewbyid(r.id.single);order = (radiobutton)findviewbyid(r.id.order);radom = (radiobutton)findviewbyid(r.id.radom);radiogroup
6、= (radiogroup)findviewbyid(r.id.menu);radiogroup.setoncheckedchangelistener(new oncheckedchangelistener() overridepublic void oncheckedchanged(radiogroup group, int checkedid) / todo auto-generated method stubif(checkedid = single.getid()mode = appconstant.jump_mode_single;else if(checkedid = order.
7、getid()mode = appconstant.jump_mode_order;else if(checkedid = radom.getid()mode = appconstant.jump_mode_radom;);overrideprotected void onlistitemclick(listview l, view v, int position, long id) / todo auto-generated method stubsuper.onlistitemclick(l, v, position, id);/mpsiterm mp3=mp3s.get(position
8、);intent preintent = new intent();preintent.putextra(position, position);preintent.putextra(cmd, appconstant.jump_cmd_prepare);preintent.putextra(mode, mode);preintent.setclass(localmpslist.this, listsrv.class);startservice(preintent);/*intent intent=new intent();intent.putextra(mp3, mp3);intent.set
9、class(this, mpsplayer.class);startactivity(intent);*/onstop();overrideprotected void onresume() / todo auto-generated method stubsuper.onresume();updatelistview();overrideprotected void onstop() / todo auto-generated method stubsuper.onstop();finish();private void updatelistview()fileutils fileutils
10、=new fileutils();mp3s=fileutils.getmp3files(mp3);if (mp3s=null)/如果本地目录找不到mp3文件mp3s=new arraylist();mpsiterm mp3=new mpsiterm();mp3.setname_mp3(没有mp3文件!);mp3.setsize_mp3(0);mp3s.add(mp3);adapterutils au=new adapterutils(this,r.layout.mp3info_item,mp3s);simpleadapter simpleadapter=au.buildsimpleadapte
11、r();setlistadapter(simpleadapter);itractivity.javapackage sled.develop;import android.app.activity;import android.os.bundle;public class itractivity extends activityoverrideprotected void oncreate(bundle savedinstancestate) / todo auto-generated method stubsuper.oncreate(savedinstancestate);setconte
12、ntview(r.roduction);overrideprotected void onstop() / todo auto-generated method stubsuper.onstop();finish();mpsplayer.javapackage sled.develop;import sled.develop.service.listsrv;import sled.develop.service.playersrv;import sled.utils.appconstant;import android.app.activity;import android
13、.content.broadcastreceiver;import android.content.context;import android.content.intent;import android.content.intentfilter;import android.graphics.bitmap;import android.graphics.bitmapfactory;import android.media.audiomanager;import android.os.bundle;import android.os.handler;import android.view.me
14、nu;import android.view.menuitem;import android.view.motionevent;import android.view.view;import android.view.view.onclicklistener;import android.widget.imagebutton;import android.widget.imageview;import android.widget.linearlayout;import android.widget.seekbar;import android.widget.textview;public c
15、lass mpsplayer extends activity implements appconstant private audiomanager am = null ;private intentfilter intentfilter=null;private broadcastreceiver receiver=null;private intent playintent=null;private intent intentnext = null ;private thread t = null ;private linearlayout ll = null;private image
16、button last_btn = null ;private imagebutton pause_btn = null ;private imagebutton play_btn = null ;private imagebutton next_btn = null ;private imagebutton list_btn = null ;private seekbar seekbar = null ;private textview time_view = null ;private textview lrc_view = null ;private textview mp3info_v
17、iew = null ;private imageview song_img = null ;private imageview volbar = null ;private imageview logo = null ;private int sysmaxvolume , curvolume;private int vol_id = r.drawable.vol_0,r.drawable.vol_1,r.drawable.vol_2,r.drawable.vol_3,r.drawable.vol_4,r.drawable.vol_5,r.drawable.vol_6,r.drawable.v
18、ol_7;private int logo_id = r.drawable.logo_0,r.drawable.logo_1,r.drawable.logo_2,;int logo_index = 0 ;float downx = 0 ;float downy = 0 ;float upx = 0 ;float upy = 0 ;float relatex ;float relatey ;long tempt = 0 ;long downt = 0 ;long movet = 0 ;long upt = 0 ;private float click_pointor = 80 ;/int cou
19、nt = 0 ;overrideprotected void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate);setcontentview(r.layout.main);ll = (linearlayout)findviewbyid(r.id.control_view);last_btn = (imagebutton)findviewbyid(r.id.last);last_btn.setonclicklistener(new lastonclicklistener();pause_btn = (im
20、agebutton)findviewbyid(r.id.pause);pause_btn.setonclicklistener(new pauseonclicklistener();play_btn = (imagebutton)findviewbyid(r.id.play);play_btn.setonclicklistener(new playonclicklistener();next_btn = (imagebutton)findviewbyid(r.id.next);next_btn.setonclicklistener(new nextonclicklistener();list_
21、btn = (imagebutton)findviewbyid(r.id.list);list_btn.setonclicklistener(new listonclicklistener();seekbar = (seekbar)findviewbyid(r.gressbar);seekbar.setonseekbarchangelistener(new seekbarlistener();time_view = (textview)findviewbyid(r.id.timeview);lrc_view = (textview)findviewbyid(r.id.lrcview
22、);mp3info_view = (textview)findviewbyid(r.id.mp3_info);song_img = (imageview)findviewbyid(r.id.img_of_the_song);volbar = (imageview)findviewbyid(r.id.volfasebar);logo = (imageview)findviewbyid(r.id.logo);overrideprotected void onresume() super.onresume();am = (audiomanager)getsystemservice(context.a
23、udio_service);sysmaxvolume = am.getstreammaxvolume(audiomanager.stream_music);receiver=new lrcmessbroadcastreceiver();/两个参数,一个是指明操作,一个是指明过滤registerreceiver(receiver,getintentfilter();initplayersrv();initlistsrv();dosomething(null,null);override public boolean oncreateoptionsmenu(menu menu) / todo au
24、to-generated method stub menu.add(0, 1, 1, 操作说明); menu.add(0, 2, 2, 完全退出); return super.oncreateoptionsmenu(menu); override public boolean onoptionsitemselected(menuitem item) / todo auto-generated method stub if(item.getitemid() = 1) intent tintent = new intent(); tintent.setclass(mpsplayer.this, i
25、tractivity.class); startactivity(tintent); else if(item.getitemid() = 2) stopservice(playintent); stopservice(intentnext); finish(); return true; overrideprotected void onrestart() super.onrestart();protected void onpause() super.onpause();unregisterreceiver(receiver);/一些基本布局public void dosomething(
26、string mp3info,string img)bitmap bm ;if(mp3info = null | img = null )mp3info = no music selected;song_img.setimageresource(r.drawable.logo_0);mp3info_view.settext(mp3info);else/system.out.println(img);mp3info = 当前播放: + mp3info;bm = bitmapfactory.decodefile(/sdcard/mp3/img/ + img);if(bm = null)song_i
27、mg.setimageresource(r.drawable.logo_0);elsesong_img.setimagebitmap(bm);mp3info_view.settext(mp3info);/* * 一些按钮和进度条的监听方法 * author administrator * */class lastonclicklistener implements onclicklisteneroverridepublic void onclick(view v) lastmusic();class pauseonclicklistener implements onclicklistener
28、overridepublic void onclick(view v) pausemp3();/t.start();class playonclicklistener implements onclicklisteneroverridepublic void onclick(view v) initplayersrv();playmp3();class nextonclicklistener implements onclicklisteneroverridepublic void onclick(view v) nextmusic();public void initlistsrv()int
29、entnext = new intent();intentnext.setclass(mpsplayer.this, listsrv.class);public void nextmusic()intentnext.putextra(cmd, appconstant.jump_cmd_next);startservice(intentnext);public void lastmusic()intent intentnext = new intent();intentnext.putextra(cmd, appconstant.jump_cmd_last);intentnext.setclas
30、s(mpsplayer.this, listsrv.class);startservice(intentnext);class seekbarlistener implements seekbar.onseekbarchangelistener/进度条事件响应public void onprogresschanged(seekbar arg0, int arg1, boolean arg2) public void onstarttrackingtouch(seekbar arg0) public void onstoptrackingtouch(seekbar arg0) if (seekb
31、ar.getmax() 0)/是一次点击事件if(math.abs(relatex) = click_pointor & math.abs(relatey) 500)intent intent = new intent();intent.setclass(mpsplayer.this, localmpslist.class);startactivity(intent);elsell.setvisibility(view.visible);t = new thread(tr);t.start();else if(math.abs(relatex) math.abs(relatey)if(down
32、x upx)nextmusic();else if(downx upx)lastmusic();else if(math.abs(relatex) math.abs(relatey)if(downy upy)turnvol(audiomanager.adjust_raise);upt = -1 ;/upx = upy = 0 ;return super.ontouchevent(event);/代码复用,关于音量调节public void turnvol(int value)am.adjuststreamvolume (audiomanager.stream_music, value,0);c
33、urvolume = am.getstreamvolume(audiomanager.stream_music);int num_pic = (7*curvolume)/sysmaxvolume ;volbar.setimageresource(vol_idnum_pic);volbar.setvisibility(view.visible);thread thread = new thread(tv);thread.start();/* * 音量条延迟线程 */handler vhandler = new handler();runnable tv = new runnable()overr
34、idepublic void run() try thread.sleep(1000); catch (interruptedexception e) e.printstacktrace();vhandler.post(vr);runnable vr = new runnable()overridepublic void run() volbar.setvisibility(view.gone);/* * 进度条等按钮延迟线程 */handler handler = new handler();runnable tr = new runnable()overridepublic void ru
35、n() try thread.sleep(5000); catch (interruptedexception e) e.printstacktrace();handler.post(r);runnable r = new runnable() overridepublic void run() ll.setvisibility(view.gone);listsrv.javapackage sled.develop.service;import java.util.arraylist;import java.util.random;import sled.model.mpsiterm;import sled.utils.appconstant;import sled.utils.fileutils;import android.app.service;import android.content.intent;import android.os.ibinder;public class listsrv e
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二五年度车辆绿色出行补贴购买合同
- 二零二五年度经典实习合同(法律事务实习)
- 2025年度证券公司内部控制体系建设及风险管理体系优化委托合同
- 二零二五年度金融机构与个人客户协议存款业务合同
- 二零二五年度版水库鱼塘承包与渔业养殖技术培训合同
- 2025年度项目管理顾问聘用合同书
- 二零二五年度演出活动艺人合同解除及免责合同
- 2025年度私人车位租赁与车位租赁期限调整合同
- 2025年度解聘劳动合同补偿标准与员工终身学习支持合同
- 2025年度文化创意园区车位使用权共享与开发合同
- 机电安装工程安全培训
- 洗浴部前台收银员岗位职责
- 2024年辅警考试公基常识300题(附解析)
- GB/T 43650-2024野生动物及其制品DNA物种鉴定技术规程
- 暴发性心肌炎查房
- 工程质保金返还审批单
- 【可行性报告】2023年电动自行车项目可行性研究分析报告
- 五月天歌词全集
- 商品退换货申请表模板
- 实习单位鉴定表(模板)
- 数字媒体应用技术专业调研方案
评论
0/150
提交评论