基于Android系统的音乐播放器设计与实现含源程序.doc

上传人:文库蛋蛋多 文档编号:2394077 上传时间:2023-02-17 格式:DOC 页数:47 大小:160.50KB
返回 下载 相关 举报
基于Android系统的音乐播放器设计与实现含源程序.doc_第1页
第1页 / 共47页
基于Android系统的音乐播放器设计与实现含源程序.doc_第2页
第2页 / 共47页
基于Android系统的音乐播放器设计与实现含源程序.doc_第3页
第3页 / 共47页
基于Android系统的音乐播放器设计与实现含源程序.doc_第4页
第4页 / 共47页
基于Android系统的音乐播放器设计与实现含源程序.doc_第5页
第5页 / 共47页
点击查看更多>>
资源描述

《基于Android系统的音乐播放器设计与实现含源程序.doc》由会员分享,可在线阅读,更多相关《基于Android系统的音乐播放器设计与实现含源程序.doc(47页珍藏版)》请在三一办公上搜索。

1、基于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.classpathAndr

2、oidManifest.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 androi

3、d.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 Lo

4、calMpsList 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 me

5、thod 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)findViewBy

6、Id(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 = AppConstan

7、t.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

8、 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.cl

9、ass);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=fi

10、leUtils.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(simpl

11、eAdapter);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.layout.introduc

12、tion);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.BroadcastReceiv

13、er;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.M

14、enuItem;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 A

15、ctivity 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 ;

16、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 Imag

17、eView 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

18、 = 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 ;Overrideprotecte

19、d 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

20、.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)findV

21、iewById(R.id.list);list_btn.setOnClickListener(new ListOnclickListener();seekbar = (SeekBar)findViewById(R.id.progressbar);seekbar.setOnSeekBarChangeListener(new SeekBarListener();time_view = (TextView)findViewById(R.id.timeview);lrc_view = (TextView)findViewById(R.id.lrcview);mp3info_view = (TextVi

22、ew)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);SysMaxVolu

23、me = 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

24、 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); start

25、Activity(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 im

26、g)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.dr

27、awable.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 onCl

28、ick(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();i

29、ntentnext.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, ListSr

30、v.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()1) return;if

31、(playIntent=null)initPlayerSrv();playIntent.putExtra(startTime,arg0.getProgress() );playIntent.putExtra(mediaCmd, AppConstant.MEDIA_CMD_SEEKTO);startService(playIntent);if (receiver=null)receiver=new LrcMessBroadcastReceiver();/两个参数,一个是指明操作,一个是指明过滤registerReceiver(receiver,getIntentFilter();class Li

32、stOnclickListener implements OnClickListenerOverridepublic void onClick(View v) Intent intent = new Intent();intent.setClass(MpsPlayer.this, LocalMpsList.class);startActivity(intent);/* * 一些基本操作,为方便代码复用 */开始Serviceprivate void initPlayerSrv()playIntent =new Intent();playIntent.setClass(MpsPlayer.thi

33、s,PlayerSrv.class);/发送播放操作给Serviceprivate void playMp3() playIntent.putExtra(mediaCmd, AppConstant.MEDIA_CMD_PLAY);startService (playIntent);/发送暂停操作给Serviceprivate void pauseMp3() playIntent.putExtra(mediaCmd, AppConstant.MEDIA_CMD_PAUSE);startService (playIntent);/得到广播的Itentprivate IntentFilter get

34、IntentFilter()if (intentFilter=null)intentFilter=new IntentFilter();intentFilter.addAction(AppConstant.LRC_MESSAGE_ACTION);return intentFilter;/换算歌曲时间private String getTimeStr(long offsetTime,boolean isLongFormat)int remainder=0;int mode=0;remainder=(int)offsetTime) / (60 * 1000);String min=remainde

35、r +;mode=(int)offsetTime) % (60 * 1000);remainder=mode / 1000;String sec=remainder +;if (isLongFormat)mode=mode % 1000;String mill=mode/10 +;return min +: +sec + . +mill;elsereturn min +: +sec;/* * 捕获广播和触屏事件的方法 * author Administrator * */更新歌词,时间,进度条等控件class LrcMessBroadcastReceiver extends Broadcast

36、ReceiverOverridepublic void onReceive(Context arg0, Intent arg1) logo.setImageResource(logo_idlogo_index+%logo_id.length);int uiCmd=arg1.getIntExtra(uiCmd, AppConstant.UI_CMD_UPDATELRC);if (uiCmd=AppConstant.UI_CMD_UPDATELRC)String lrcMess=arg1.getStringExtra(lrcMess);lrc_view.setText(lrcMess);else if (uiCmd=AppConstant.UI_CMD_UPDATEPLAYING)long currPos=arg1.getLongExtra(currPos, 0);int duration = arg1.

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号