android开发音乐盒的实验报告.doc_第1页
android开发音乐盒的实验报告.doc_第2页
android开发音乐盒的实验报告.doc_第3页
android开发音乐盒的实验报告.doc_第4页
android开发音乐盒的实验报告.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

开发一个安卓软件报告报告设 计 题 目: 用安卓开发单机音乐盒 学 院 名 称: 电子与信息工程学院 专 业: 计算机科学与技术 班 级: 计科091 姓 名:* 学 号 03 指 导 教 师: * 定稿日期: 2011年12月 26日一、 设计任务与要求1、设计目标:(1)了解Java编程的基础知识和数据库知识(2) 掌握用android开发应用软件的的一般步骤和方法。(3) 能够利用所学的基本知识,设计一个完整的音乐播放盒,还可以实现后台播放声音,并且在播放过程中可以通过前台的按钮控制声音的播放、暂停与关闭。(4)在以上基础上再加一个界面,能够实现跳转,出现一个歌词界面。2、课程设计的要求:1、 用Service组件、BroadcastReceiver组件、Intent、菜单对话框来完成音乐的播放等操作。2、 提交设计报告一份(需求分析、设计的基本思路、设计的步骤及主要代码、心得体会)。二、系统分析1、需求分析随着android手机的普及和一些小游戏的流行,android开发也日益high了。现在,大家也都是用手机听音乐了,一个绚丽的、酷酷的音乐盒就可以成为我们炫耀的资本了。为了符合更多人的喜欢,设计的界面要清晰、美观、大方、并且操作方便。所以我设计的界面也一定要清晰、美观、大方、并且操作方便。2、模块分析(1)在layout文件中增加一个歌词的界面songwords.xml并画好界面,还要在mail.xml中画好界面。(2)在raw文件中放入歌曲。我爱他 叮当 歌词 他的轻狂留在 某一节车厢 地下铁里的风 比回忆还重 省部分歌词 若那一刻重来 我不哭 让他知道我可以 很好 (3)在values文件中的string中添加所要用到的字符串。(4)在src文件中的文件中的Sample_9_3.java中定义一些按钮和转换的方法,在MyService.java中实现了按钮,在songwords.java中实现了歌词那个界面的功能。三、系统设置1、功能设计这个播放器可以实现播放,暂停,停止和歌词界面跳转功能。在刚打开音乐盒的时候,是播放状态,按一下暂停按钮,音乐停止播放,且暂停按钮的图像变为播放按钮的图像;此时再按一下播放按钮,音乐继续;无论音乐在播放状态还是暂停状态,只要按一下停止按钮,音乐就会被关闭;当音乐在播放时,按歌词按钮,就会跳转到当前播放的歌的歌词界面,且音乐继续在播放;如果退出音乐盒这个界面,音乐也还是再继续的。而且在还没有跳转的时候,按菜单栏就会出现退出前台的按钮了。2、界面设计第一个界面总体分为上、下两层,第一层主要分三个部分,把播放按钮和暂停按钮重叠的放在第一部分,把停止按钮放在第二部分,第三部分又划分成上、下两个部分,上面放歌曲的名称,下面放歌曲的演唱者;第二层只有一个按钮,跳转到歌词界面的功能。 第二个界面也分为上、下两层,第一层就是用来放歌词的;第二层有一个返回按钮,可以返回到第一个界面。 最终的效果是:四、个人总结这个音乐盒虽然比较简单,但是是我自己用这个学期所学到的知识来完成的,有我自己的心血,让自己觉得自己还不错。在做实验的过程也遇到了问题,毕竟所学的知识不是很深,问了在暑假所过的同学很多问题,终于完成了。在做音乐盒的过程中,先前想得很简单,只要它能播放、暂停、停止就可以了。后来想想要是可以看到歌词就好了,所以才加的歌词那个界,还把字体设置成了自己喜欢的枚红色。本来还想在歌词按钮的下面再加一个列表,来显示所有的歌曲名及其演唱者,但是自己的知识还是太少了,没能把它实现。不过还是会再接再砺的。五、附录:代码4、修改Music.java源代码:public class Music extends Activity implements OnClickListenerImageButton start;/播放、暂停按钮ImageButton stop;/停止按钮private Button swords;ActivityReceiver activityReceiver;int status = 1;/当前的状态,1没有声音播放 ,2 正在播放声音,3暂停 /* Called when the activity is first created. */ Override public void onCreate(Bundle savedInstanceState) /重写的onCreate方法 super.onCreate(savedInstanceState); setContentView(R.layout.main);/设置当前的用户界面 start = (ImageButton) this.findViewById(R.id.start);/得到start的引用 stop = (ImageButton) this.findViewById(R.id.stop);/得到stop按钮的引用 swords = (Button) this.findViewById(R.id.swords); start.setOnClickListener(this);/为按钮添加监听 stop.setOnClickListener(this);/为按钮添加监听 swords.setOnClickListener(this); activityReceiver = new ActivityReceiver();/创建BroadcastReceiver IntentFilter filter = new IntentFilter();/创建IntentFilter过滤器 filter.addAction(wyf.ytl.update);/添加Action registerReceiver(activityReceiver, filter);/注册监听 Intent intent = new Intent(this, MyService.class);/创建Intent startService(intent);/启动后台Service public class ActivityReceiver extends BroadcastReceiver/自定义的BroadcastReceiverOverridepublic void onReceive(Context context, Intent intent) /重写的onReceive方法/ TODO Auto-generated method stubint update = intent.getIntExtra(update, -1);/得到intent中的数据switch(update)/分支判断case 1:/没有声音播放status = 1; /设置当前状态break;case 2:/正在播放声音start.setImageResource(R.drawable.png3);/更换图片status = 2; /设置当前状态break;case 3:/暂停中start.setImageResource(R.drawable.png2);/更换图片status = 3; /设置当前状态break; Overridepublic void onClick(View v) /接口中的方法/ TODO Auto-generated method stubIntent intent = new Intent(wyf.ytl.control);/创建Intentswitch(v.getId()/分支判断case R.id.start:/按下播放、暂停按钮intent.putExtra(ACTION, 1);/存放数据sendBroadcast(intent);/发送广播break;case R.id.stop:/按下停止按钮intent.putExtra(ACTION, 2);/存放数据sendBroadcast(intent);/发送广播break;case R.id.swords:Intent intent2=new Intent();intent2.setClass(this, Songwords.class);startActivity(intent2);Overrideprotected void onDestroy() /释放时被调用/ TODO Auto-generated method stubsuper.onDestroy(); Intent intent = new Intent(this, MyService.class);/创建Intent stopService(intent);/停止后台的ServiceOverridepublic boolean onCreateOptionsMenu(Menu menu)/弹出菜单 menu.add(0,Menu.FIRST,0,退出).setIcon(R.drawable.ic_menu_delete);/设置图标return true;Overridepublic boolean onOptionsItemSelected(MenuItem item)/选择的菜单项switch(item.getItemId()/分支判断case Menu.FIRST:showDialog(1);/显示对话框break;/将来可在此进行扩展return false;Overrideprotected Dialog onCreateDialog(int id)/创建对话框switch(id)/判断case 1:return new AlertDialog.Builder(this).setTitle(您确定退出?).setPositiveButton(确定, new android.content.DialogInterface.OnClickListener()Overridepublic void onClick(DialogInterface dialog, int which) / TODO Auto-generated method stubSystem.exit(0);/直接退出).setNegativeButton(取消, null)/取消按钮.create();default:return null;5、修改Myservice.java源代码:package wyf.ytl;public class MyService extends ServiceMediaPlayer mp;ServiceReceiver serviceReceiver;int status = 1;/当前的状态,1没有声音播放 ,2 正在播放声音,3暂停Overridepublic IBinder onBind(Intent intent) /重写的onBind方法/ TODO Auto-generated method stubreturn null;Overridepublic void onCreate() /重写的onCreate方法,会在Service创建时被调用/ TODO Auto-generated method stubstatus = 1;serviceReceiver = new ServiceReceiver();/创建BroadcastReceiverIntentFilter filter = new IntentFilter();/创建过滤器filter.addAction(wyf.ytl.control);/添加ActionregisterReceiver(serviceReceiver, filter);/注册BroadcastReceiversuper.onCreate();Overridepublic void onDestroy() /重写的onDestroy方法/ TODO Auto-generated method stubunregisterReceiver(serviceReceiver);/取消注册super.onDestroy();public class ServiceReceiver extends BroadcastReceiver/自定义BroadcastReceiverOverridepublic void onReceive(Context context, Intent intent) /重写的响应方法/ TODO Auto-generated method stubint action = intent.getIntExtra(ACTION, -1);/得带需要的数据switch(action)case 1:/播放或暂停声音if(status = 1)/当前没有声音播放mp = MediaPlayer.create(context, R.raw.nx);status = 2;Intent sendIntent = new Intent(wyf.ytl.update);sendIntent.putExtra(update, 2);sendBroadcast(sendIntent);mp.start();else if(status = 2)/正在播放声音mp.pause();/停止status = 3;/改变状态 Intent sendIntent = new Intent(wyf.ytl.update);sendIntent.putExtra(update, 3);/存放数据sendBroadcast(sendIntent);/发送广播else if(status = 3)/暂停中mp.start();/播放声音status = 2;/改变状态Intent sendIntent = new Intent(wyf.ytl.update);sendIntent.putExtra(update, 2);/存放数据sendBroadcast(sendIntent);/发送广播break;case 2:/停止声音if(status = 2 | status = 3)/播放中或暂停中mp.stop();/停止播放status = 1;/改变状态Intent sendIntent = new Intent(wyf.ytl.update);sendIntent.putExtra(update, 1);/存放数据sendBroadcast(sendIntent);/发送广播6、增加Songwords.java的源代码:public class Songwords extends Activit

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论