资源描述
音乐播放器源程序清单Java
目录
1引言1
1.1标题 1
1.2模块开发情况表 1
2模块1(UI的设计)1
2.1功能说明 1
2.2设计说明 1
2.3源代码清单 2
3模块二(音乐列表的设计)6
3.1功能说明 6
3.2 设计说明 6
3.3 源代码清单 6
4模块三(音乐扫描的设计)8
4.1 功能说明 8
4.2 设计说明 8
4.3 源代码清单 8
5模块四(播放暂停设计)9
5.1 功能说明 9
5.2 设计说明 9
5.3 源代码清单 10
6模块五(音量加减设计)11
6.1 功能说明 11
6.2 设计说明 11
6.3源代码清单 11
19 / 22
1引言
1.1标题
安卓音乐播放器软件设计软件工程数据库课程设计
1.2模块开发情况表
功能结构设计如下:
(1)启动界面
(2)播放界面:播放,快进,快退,暂停,上一个,下一个,进度条
(3)播放模式:单曲循环,循环播放,随机播放
(4)缩放:4:3,16:9,全屏
(5)播放列表:存于数据库中,并且排序显示,正在播放的视频要有区分
(6)缩略图
(7)任意级目录
(8)喜好界面
(9)主题
(10)天气预报
2模块1(UI的设计)
2.1功能说明
系统UI的设计如下:
2.2设计说明
设计程序主界面,增加主界面的美观,以及和用户之间的交互性。通过UI设计UML文件设计,使用控件布局,代码相结合。完美设计出主界面。
主界面明确了当,直接的显示出可操作的按钮。让用户更加简单,使用本软件。
界面如下:
2.3源代码清单
Uml 布局代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="fill"
android:background="#000000">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="80" >
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#E61344"
android:layout_weight="25"
android:layout_marginBottom="2dp"
>
</ListView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="75" >
<Button
android:id="@+id/liebiao1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/liebiao"
android:layout_marginLeft="2dp"
android:layout_marginBottom="2dp" />
<Button
android:id="@+id/zengyin1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/jiayin"
android:layout_marginLeft="2dp"
android:layout_marginBottom="2dp" />
<Button
android:id="@+id/jianyin1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/jianyin"
android:layout_marginLeft="2dp"
android:layout_marginBottom="2dp" />
<Button
android:id="@+id/guanji"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/guanji"
android:layout_marginLeft="2dp"
android:layout_marginBottom="2dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="5" >
<Button
android:id="@+id/bofang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/bofang"
android:layout_marginRight="1dp"
android:layout_marginBottom="2dp"/>
<Button
android:id="@+id/zanting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/zanting"
android:layout_marginLeft="1dp"
android:layout_marginBottom="2dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="5" >
<Button
android:id="@+id/shangyiqu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/shangyiqu"
android:layout_marginRight="1dp"
/>
<Button
android:id="@+id/xiayiqu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/xiyishou"
android:layout_marginLeft="1dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Java代码如下
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main3);
3模块二(音乐列表的设计)
3.1功能说明
播放列表有存放音乐文件,点击音乐文,即可播放。
3.2 设计说明
播放列表中存放音乐文件名字,点击文件名字,即可播放音乐,列表存放的方式是数列模式。
3.3 源代码清单
UML代码:
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#E61344"
android:layout_weight="25"
android:layout_marginBottom="2dp"
</ListView>
Java代码:
private List<String> audioList = new ArrayList<String>(); // 要播放的音频列表
@SuppressLint("SdCardPath")
privatevoid audioList() {
getFiles("/sdcard/"); // 获取SD卡上的全部音频文件
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, audioList); // 创建一个适配器
ListView listview = (ListView) findViewById(R.id.list); // 获取布局管理器中添加的ListView组件
listview.setAdapter(adapter); // 将适配器及ListView关联
// 当单击列表项时播放音乐
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
publicvoid onItemClick(AdapterView<?> listView, View view,
int position, long id) {
currentItem = position; // 将当前列表项的索引值赋值给currentItem
playMusic(MUSIC_PATH+audioList.get(currentItem)); // 调用playMusic()方法播放音乐
}
});
}
4模块三(音乐扫描的设计)
4.1 功能说明
点击扫描音乐按钮,进行音乐文件扫描,扫描SD卡上的所有MP3格式的音乐文件。将扫描后的音乐文件加载到播放列表中。
4.2 设计说明
本段程序是将SD卡上的音乐文件,进行扫描,并将文件加载到播放列表中。
4.3 源代码清单
UML 代码:
<Button
android:id="@+id/bofang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/bofang"
android:layout_marginRight="1dp"
android:layout_marginBottom="2dp"/>
Java 代码:
privatevoid getFiles(String url) {
= new ); // 创建文件对象
File[] file = ();
try {
for (File f : file) { // 通过for循环遍历获取到的文件数组
if (f.isDirectory()) { // 如果是目录,也就是文件夹
getFiles(f.getAbsolutePath()); // 递归调用
} else {
if (isAudio())) { // 如果是音频文件
audioList.add(f.getName()); // 将文件的路径添加到list集合中
}
}
}
} catch (Exception e) {
e.printStackTrace(); // 输出异常信息
}
}
privatestatic String[] imageFormatSet = new String[] { ".mp3" }; // 合法的音频文件格式
// 判断是否为音频文件
privatestaticboolean isAudio path) {
for (String format : imageFormatSet) { // 遍历数组
if (path.contains(format)) { // 判断是否为有合法的音频文件
returntrue;
}
}
returnfalse;
}
5模块四(播放暂停设计)
5.1 功能说明
当点击音乐播放/暂停按钮的候,点击一下,音乐会播放,再点击以下,音乐会暂停。
5.2 设计说明
本段程序实现了播放音乐和暂停音乐的功能,当点击音乐播放/暂停按钮的候,点击一下,音乐会播放,再点击以下,音乐会暂停。
5.3 源代码清单
UML 代码:
<Button
android:id="@+id/zanting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/zanting"
android:layout_marginLeft="1dp"
android:layout_marginBottom="2dp"/>
Java 代码:
pause.setOnClickListener(new OnClickListener() {
@Override
publicvoid onClick(View v) {
if (mediaPlayer.isPlaying()) {
mediaPlayer.pause(); // 暂停视频的播放
((Button) v).setText("继续");
} else {
mediaPlayer.start(); //继续播放
((Button) v).setText("暂停");
}
}
});
// 播放音乐
void playMusic(String Path) {
try {
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop(); // 停止当前音频的播放
}
mediaPlayer.reset(); // 重置MediaPlayer
mediaPlayer.setDataSource(Path); // 指定要播放的音频文件
mediaPlayer.prepare(); // 预加载音频文件
mediaPlayer.start(); // 播放音频
pause.setText("暂停");
pause.setEnabled(true); // 设置“暂停”按钮可用
} catch (Exception e) {
e.printStackTrace();
}
}
6模块五(音量加减设计)
6.1 功能说明
当点击增加音乐按钮的时候,音量就会增加,当点击音乐减少按钮的时候,音量就会减少。
6.2 设计说明
本段程序实现了音乐音量的增加和减少的功能,当点击增加音乐按钮的时候,音量就会增加,当点击音乐减少按钮的时候,音量就会减少。
6.3源代码清单
UML 代码:
<Button
android:id="@+id/zengyin1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/jiayin"
android:layout_marginLeft="2dp"
android:layout_marginBottom="2dp" />
<Button
android:id="@+id/jianyin1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/jianyin"
android:layout_marginLeft="2dp"
android:layout_marginBottom="2dp" />
Java 代码:
private AudioManager audioManager; // 系统声音管理类
Button zeng = (Button) findViewById(R.id.zengyin1);
Button jian = (Button) findViewById(R.id.jianyin1);
zeng.setOnClickListener(new OnClickListener() {
@Override
publicvoid onClick(View v) { audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,AudioManager.ADJUST_RAISE , AudioManager.FLAG_SHOW_UI);
}
});
jian.setOnClickListener(new OnClickListener() {
@Override
publicvoid onClick(View v) { audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,AudioManager.ADJUST_LOWER , AudioManager.FLAG_SHOW_UI);
}
});
7模块六 (上一曲/下一曲设计)
7.1 功能说明
当点击上一曲或下一曲的时候,播放器会对播放列表的文件进行上一曲或下一曲的播放。
7.2 设计说明
本段程序实现音乐上一曲下一曲的播放,当点击上一曲或下一曲的时候,播放器会对播放列表的文件进行上一曲或下一曲的播放。
7.3 代码清单
UML 代码:
<Button
android:id="@+id/shangyiqu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/shangyiqu"
android:layout_marginRight="1dp"
/>
<Button
android:id="@+id/xiayiqu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/xiyishou"
android:layout_marginLeft="1dp"/>
Java 代码:
// 下一首
void nextMusic() {
if (++currentItem >= audioList.size()) {// 当对currentItem进行+1操作后,如果其值大于等于音频文件的总数
currentItem = 0;
}
playMusic(MUSIC_PATH+audioList.get(currentItem)); // 调用playMusic()方法播放音乐
}
// 上一首
void preMusic() {
if (--currentItem >= 0) { // 当对currentItem进行-1操作后,如果其值大于等于0
if (currentItem >= audioList.size()) { // 如果currentItem的值大于等于音频文件的总数
currentItem = 0;
}
} else {
currentItem = audioList.size() - 1; // currentItem的值设置为音频文件总数-1
}
playMusic(MUSIC_PATH+audioList.get(currentItem)); // 调用playMusic()方法播放音乐
}
展开阅读全文