初次提交
This commit is contained in:
7
第2章 游戏开发基础知识/Sample2_2/.classpath
Normal file
7
第2章 游戏开发基础知识/Sample2_2/.classpath
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
33
第2章 游戏开发基础知识/Sample2_2/.project
Normal file
33
第2章 游戏开发基础知识/Sample2_2/.project
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Sample2_2</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
12
第2章 游戏开发基础知识/Sample2_2/.settings/org.eclipse.jdt.core.prefs
Normal file
12
第2章 游戏开发基础知识/Sample2_2/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,12 @@
|
||||
#Fri Jul 01 07:55:04 CST 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
17
第2章 游戏开发基础知识/Sample2_2/AndroidManifest.xml
Normal file
17
第2章 游戏开发基础知识/Sample2_2/AndroidManifest.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" package="com.bn.pp2">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<activity android:name=".Sample2_2_Activity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
|
||||
|
||||
</manifest>
|
||||
BIN
第2章 游戏开发基础知识/Sample2_2/bin/Sample2_2.apk
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/Sample2_2.apk
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/classes.dex
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/classes.dex
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/R$attr.class
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/R$attr.class
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/R$drawable.class
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/R$drawable.class
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/R$id.class
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/R$id.class
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/R$layout.class
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/R$layout.class
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/R$string.class
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/R$string.class
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/R.class
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/R.class
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/Sample2_2_Activity$1.class
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/Sample2_2_Activity$1.class
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/Sample2_2_Activity$2.class
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/Sample2_2_Activity$2.class
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/Sample2_2_Activity$3.class
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/Sample2_2_Activity$3.class
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/Sample2_2_Activity$4.class
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/Sample2_2_Activity$4.class
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/Sample2_2_Activity$5.class
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/Sample2_2_Activity$5.class
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/Sample2_2_Activity.class
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/com/bn/pp2/Sample2_2_Activity.class
Normal file
Binary file not shown.
BIN
第2章 游戏开发基础知识/Sample2_2/bin/resources.ap_
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/bin/resources.ap_
Normal file
Binary file not shown.
11
第2章 游戏开发基础知识/Sample2_2/default.properties
Normal file
11
第2章 游戏开发基础知识/Sample2_2/default.properties
Normal file
@@ -0,0 +1,11 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "build.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-7
|
||||
30
第2章 游戏开发基础知识/Sample2_2/gen/com/bn/pp2/R.java
Normal file
30
第2章 游戏开发基础知识/Sample2_2/gen/com/bn/pp2/R.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*
|
||||
* This class was automatically generated by the
|
||||
* aapt tool from the resource data it found. It
|
||||
* should not be modified by hand.
|
||||
*/
|
||||
|
||||
package com.bn.pp2;
|
||||
|
||||
public final class R {
|
||||
public static final class attr {
|
||||
}
|
||||
public static final class drawable {
|
||||
public static final int icon=0x7f020000;
|
||||
}
|
||||
public static final class id {
|
||||
public static final int Button01=0x7f050000;
|
||||
public static final int Button02=0x7f050001;
|
||||
public static final int Button03=0x7f050002;
|
||||
public static final int Button04=0x7f050003;
|
||||
public static final int Button05=0x7f050004;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int main=0x7f030000;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int app_name=0x7f040001;
|
||||
public static final int hello=0x7f040000;
|
||||
}
|
||||
}
|
||||
BIN
第2章 游戏开发基础知识/Sample2_2/res/drawable-hdpi/icon.png
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/res/drawable-hdpi/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
BIN
第2章 游戏开发基础知识/Sample2_2/res/drawable-ldpi/icon.png
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/res/drawable-ldpi/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
BIN
第2章 游戏开发基础知识/Sample2_2/res/drawable-mdpi/icon.png
Normal file
BIN
第2章 游戏开发基础知识/Sample2_2/res/drawable-mdpi/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
43
第2章 游戏开发基础知识/Sample2_2/res/layout/main.xml
Normal file
43
第2章 游戏开发基础知识/Sample2_2/res/layout/main.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="简单音乐播放器"
|
||||
/>
|
||||
<Button
|
||||
android:text="播放音乐"
|
||||
android:id="@+id/Button01"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
</Button>
|
||||
<Button
|
||||
android:text="暂停播放"
|
||||
android:id="@+id/Button02"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
</Button>
|
||||
<Button
|
||||
android:text="停止播放"
|
||||
android:id="@+id/Button03"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
</Button>
|
||||
<Button
|
||||
android:text="增大音量"
|
||||
android:id="@+id/Button04"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
</Button>
|
||||
<Button
|
||||
android:text="减小音量"
|
||||
android:id="@+id/Button05"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
</Button>
|
||||
</LinearLayout>
|
||||
5
第2章 游戏开发基础知识/Sample2_2/res/values/strings.xml
Normal file
5
第2章 游戏开发基础知识/Sample2_2/res/values/strings.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="hello">Hello World, Sample3_7_Activity!</string>
|
||||
<string name="app_name">Sample2_2</string>
|
||||
</resources>
|
||||
112
第2章 游戏开发基础知识/Sample2_2/src/com/bn/pp2/Sample2_2_Activity.java
Normal file
112
第2章 游戏开发基础知识/Sample2_2/src/com/bn/pp2/Sample2_2_Activity.java
Normal file
@@ -0,0 +1,112 @@
|
||||
package com.bn.pp2;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class Sample2_2_Activity extends Activity {
|
||||
MediaPlayer mp; // 声明MediaPlayer的引用
|
||||
AudioManager am; // 声明AudioManager的引用
|
||||
private int maxVolume; // 最大音量值
|
||||
private int currVolume; // 当前音量值
|
||||
private int stepVolume; // 每次调整的音量幅度
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) // 重写onCreate方法
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main); // 设置layout
|
||||
mp = new MediaPlayer(); // 创建MediaPlayer实例对象
|
||||
try {
|
||||
mp.setDataSource("/sdcard/gsls.mp3"); // 为MediaPlayer设置要播放文件资源
|
||||
mp.prepare(); // MediaPlayer进行缓冲准备
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); // 获取AudioManager对象引用
|
||||
// 获取最大音乐音量
|
||||
maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
// 每次调整的音量大概为最大音量的1/6
|
||||
stepVolume = maxVolume / 6;
|
||||
|
||||
Button bstart = (Button) this.findViewById(R.id.Button01); // 获取开始按钮
|
||||
bstart.setOnClickListener // 为开始按钮添加监听器
|
||||
(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mp.start(); // 调用MediaPlayer的start方法来播放音乐
|
||||
Toast.makeText(getBaseContext(), "开始播放'高山流水曲'",
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
Button bpause = (Button) this.findViewById(R.id.Button02); // 获取暂停按钮
|
||||
bpause.setOnClickListener // 为暂停按钮添加监听器
|
||||
(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mp.pause(); // 调用MediaPlayer的pause方法暂停播放音乐
|
||||
Toast.makeText(getBaseContext(), "暂停播放'高山流水曲'",
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
Button bstop = (Button) this.findViewById(R.id.Button03); // 获取停止按钮
|
||||
bstop.setOnClickListener // 为停止按钮添加监听器
|
||||
(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mp.stop(); // 调用MediaPlayer的stop方法停止播放音乐
|
||||
try {
|
||||
mp.prepare();//进入准备状态
|
||||
} catch (IllegalStateException e) {//捕获异常
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {//捕获异常
|
||||
e.printStackTrace();
|
||||
}
|
||||
Toast.makeText(getBaseContext(), "停止播放'高山流水曲'",
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
Button bUp = (Button) this.findViewById(R.id.Button04); // 获取增大音量按钮
|
||||
bUp.setOnClickListener // 为增大音量按钮添加监听器
|
||||
(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 获取当前音量
|
||||
currVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
//增加音量,但不超过最大音量值
|
||||
int tmpVolume = currVolume + stepVolume; //临时音量
|
||||
currVolume = tmpVolume < maxVolume ? tmpVolume:maxVolume;
|
||||
am.setStreamVolume(AudioManager.STREAM_MUSIC, currVolume,
|
||||
AudioManager.FLAG_PLAY_SOUND);
|
||||
Toast.makeText(getBaseContext(), "增大音量",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
Button bDown = (Button) this.findViewById(R.id.Button05); // 获取减小音量按钮
|
||||
bDown.setOnClickListener // 为减小音量按钮添加监听器
|
||||
(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 获取当前音量
|
||||
currVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
//减小音量,但不小于0
|
||||
int tmpVolume = currVolume - stepVolume; //临时音量
|
||||
currVolume = tmpVolume > 0 ? tmpVolume:0;
|
||||
am.setStreamVolume(AudioManager.STREAM_MUSIC, currVolume,
|
||||
AudioManager.FLAG_PLAY_SOUND);
|
||||
Toast.makeText(getBaseContext(), "减小音量",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user