




已阅读5页,还剩42页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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.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.ListActivity;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.SimpleAdapter;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) / 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 = (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.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);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.setClass(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=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.buildSimpleAdapter();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);setContentView(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.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.Menu;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 class 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 ImageButton 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_view = 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.vol_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 count = 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 = (ImageButton)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_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);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.AUDIO_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 Auto-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, ItrActivity.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(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_img.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 OnClickListenerOverridepublic 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()intentnext = 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.setClass(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 (seekbar.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(downX 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);CurVolume = 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()Overridepublic 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 run() 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广西中马投控集团招聘42人考前自测高频考点模拟试题及答案详解(全优)
- 2025江西吉安市七叶荆文化旅游有限公司招聘安排模拟试卷附答案详解(完整版)
- 2025年安徽皖信人力招聘管内客运站12名安检工作人员考前自测高频考点模拟试题有完整答案详解
- 2025年南平邵武市医疗单位医疗类储备人才引进8人模拟试卷及答案详解(典优)
- 2025江西赣州市第五人民医院劳务派遣招聘助理护士20人模拟试卷附答案详解(黄金题型)
- 2025年宁波市鄞州区第二医院医共体招聘第二批高层次紧缺人才13人考前自测高频考点模拟试题及答案详解(必刷)
- 2025吉林长春经济技术开发区人民法院面向社会招聘审判辅助人员聘用人员模拟试卷有完整答案详解
- 2025年湖南永州市冷水滩区人民法院招聘9名聘用制审判辅助人员考前自测高频考点模拟试题完整参考答案详解
- 2025广东惠州龙门县教育局招聘教师80人考前自测高频考点模拟试题及完整答案详解
- 2025年南平邵武市立医院护理岗位招聘考前自测高频考点模拟试题有完整答案详解
- 2025内蒙古鄂尔多斯市国源矿业开发有限公司招聘75人备考考试题库附答案解析
- 2025年专升本政治试题真题及答案
- 幽门螺杆菌课件
- 元代文学-课件
- 水利法规基础知识培训课件
- 包装材质基础知识培训课件
- 2025至2030中国生产监控行业项目调研及市场前景预测评估报告
- 养老护理员学习汇报
- (新人教PEP版)英语五年级上册全册大单元教学设计
- 小儿急性阑尾炎护理查房
- 环卫车司机管理制度
评论
0/150
提交评论