android应用开发设计报告Word文档格式.docx
《android应用开发设计报告Word文档格式.docx》由会员分享,可在线阅读,更多相关《android应用开发设计报告Word文档格式.docx(11页珍藏版)》请在冰豆网上搜索。
因此为了迎合众多用户的需求并适应现在的手机的规模,我们提出了一款视频播放器,可播放一些常见格式的视频文件。
二.功能模块
三.界面设计
1.桌面图标
2.待播放界面
3.开始播放
4.暂停播放
四.分工说明
李洋宇:
编辑main代码,进行事件监听编写,文件导入
周盛蓁:
编辑layout(.xml)文件
葛一波:
程序注释,程序测试
李昀晟:
书写报告,功能检测
五.开发过程问题分析
1.界面中暂时只能实现3个功能,界面简单
2.文件只能导入.3gp格式的文件
3.在虚拟机中不能运行,必须在android2.3以上的版本才能运行
4.SD卡读取路径出现的问题,未能识别
5.软件图标对不同像素的要求
六.代码注释
1.main.xml代码注释
<
?
xmlversion="
1.0"
encoding="
utf-8"
>
LinearLayout
xmlns:
android="
android:
orientation="
vertical"
layout_width="
fill_parent"
layout_height="
>
SurfaceView
id="
@+id/surfaceView"
360px"
/>
LinearLayout
horizontal"
wrap_content"
gravity="
center_horizontal"
ImageButton
@+id/play"
src="
@drawable/play"
@+id/pause"
@drawable/pause"
@+id/stop"
@drawable/stop"
/LinearLayout>
2.strings.xml代码注释
resources>
<
stringname="
hello"
HelloWorld,SurfaceViewPlayVideo!
/string>
app_name"
PP播放器<
/resources>
3.Surfacevideoplay.java代码注释
packageorg.crazyit.sound;
importjava.io.IOException;
importandroid.app.Activity;
importandroid.media.AudioManager;
importandroid.media.MediaPlayer;
importandroid.os.Bundle;
importandroid.view.SurfaceHolder;
importandroid.view.SurfaceView;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.ImageButton;
/**
*Description:
*<
br/>
site:
ahref="
http:
//www.crazyit.org"
crazyit.org<
/a>
Copyright(C),2001-2012,Yeeku.H.Lee
Thisprogramisprotectedbycopyrightlaws.
ProgramName:
Date:
*@authorYeeku.H.Leekongyeeku@
*@version1.0
*/
publicclassSurfaceViewPlayVideoextendsActivity
implementsOnClickListener
{
SurfaceViewsurfaceView;
ImageButtonplay,pause,stop;
MediaPlayermPlayer;
//记录当前视频的播放位置
intposition;
@Override
publicvoidonCreate(BundlesavedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获取界面中的3个按钮
play=(ImageButton)findViewById(R.id.play);
pause=(ImageButton)findViewById(R.id.pause);
stop=(ImageButton)findViewById(R.id.stop);
//为3个按钮的单击事件绑定事件监听器
play.setOnClickListener(this);
pause.setOnClickListener(this);
stop.setOnClickListener(this);
//创建MediaPlayer
mPlayer=newMediaPlayer();
surfaceView=(SurfaceView)this.findViewById(R.id.surfaceView);
//设置SurfaceView自己不管理的缓冲区
surfaceView.getHolder().setType(
SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
//设置播放时打开屏幕
surfaceView.getHolder().setKeepScreenOn(true);
surfaceView.getHolder().addCallback(newSurfaceListener());
}
publicvoidonClick(Viewsource)
try
{
switch(source.getId())
{
//播放按钮被单击
caseR.id.play:
play();
break;
//暂停按钮被单击
caseR.id.pause:
if(mPlayer.isPlaying())
{
mPlayer.pause();
}
else
mPlayer.start();
//停止按钮被单击
caseR.id.stop:
mPlayer.stop();
}
}
catch(Exceptione)
e.printStackTrace();
privatevoidplay()throwsIOException
mPlayer.reset();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
//设置需要播放的视频
mPlayer.setDataSource("
/mnt/sdcard/test/bipt.3gp"
);
//把视频画面输出到SurfaceView
mPlayer.setDisplay(surfaceView.getHolder());
mPlayer.prepare();
mPlayer.start();
privateclassSurfaceListenerimplementsSurfaceHolder.Callback
@Override
publicvoidsurfaceChanged(SurfaceHolderholder,intformat,intwidth,
intheight)
publicvoidsurfaceCreated(SurfaceHolderholder)
if(position>
0)
try
{
//开始播放
//并直接从指定位置开始播放
mPlayer.seekTo(position);
position=0;
}
catch(Exceptione)
e.printStackTrace();
publicvoidsurfaceDestroyed(SurfaceHolderholder)
//当其他Activity被打开,暂停播放
protectedvoidonPause()
if(mPlayer.isPlaying())
//保存当前的播放位置
position=mPlayer.getCurrentPosition();
mPlayer.stop();
super.onPause();
protectedvoidonDestroy()
//停止播放
//释放资源
mPlayer.release();
super.onDestroy();
}