初次提交
This commit is contained in:
@@ -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>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Sample2_1</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>
|
||||
@@ -0,0 +1,12 @@
|
||||
#Fri Jul 01 07:58:27 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
|
||||
@@ -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.pp1">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<activity android:name=".Sample2_1_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>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
@@ -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.pp1;
|
||||
|
||||
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=0x7f060000;
|
||||
public static final int Button02=0x7f060001;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int main=0x7f030000;
|
||||
}
|
||||
public static final class raw {
|
||||
public static final int musictest=0x7f040000;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int app_name=0x7f050001;
|
||||
public static final int hello=0x7f050000;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
@@ -0,0 +1,28 @@
|
||||
<?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:textSize="18dip"
|
||||
android:gravity="center"
|
||||
android:text="即时音效"
|
||||
/>
|
||||
<Button
|
||||
android:text="播放音效"
|
||||
android:id="@+id/Button01"
|
||||
android:gravity="center"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
</Button>
|
||||
<Button
|
||||
android:text="停止播放"
|
||||
android:id="@+id/Button02"
|
||||
android:gravity="center"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
</Button>
|
||||
</LinearLayout>
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="hello">Hello World, Sample3_6_Activity!</string>
|
||||
<string name="app_name">Sample2_1</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.bn.pp1;
|
||||
|
||||
import java.util.HashMap;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.media.SoundPool;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class Sample2_1_Activity extends Activity {
|
||||
SoundPool sp; // 声明SoundPool的引用
|
||||
HashMap<Integer, Integer> hm; // 声明一个HashMap来存放声音文件
|
||||
int currStreamId;// 当前正播放的streamId
|
||||
|
||||
@Override
|
||||
// 重写onCreate方法
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main); // 设置layout
|
||||
initSoundPool(); // 初始化声音池的方法
|
||||
Button b1 = (Button) this.findViewById(R.id.Button01); // 获取播放按钮
|
||||
b1.setOnClickListener // 为播放按钮添加监听器
|
||||
(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
playSound(1, 0); // 播放1号声音资源,且播放一次
|
||||
// 提示播放即时音效
|
||||
Toast.makeText(getBaseContext(), "播放即时音效", Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
});
|
||||
Button b2 = (Button) this.findViewById(R.id.Button02); // 获取停止按钮
|
||||
b2.setOnClickListener // 为停止按钮添加监听器
|
||||
(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
sp.stop(currStreamId); // 停止正在播放的某个声音
|
||||
// 提示停止播放
|
||||
Toast.makeText(getBaseContext(), "停止播放即时音效", Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 初始化声音池的方法
|
||||
public void initSoundPool() {
|
||||
sp = new SoundPool(4, AudioManager.STREAM_MUSIC, 0); // 创建SoundPool对象
|
||||
hm = new HashMap<Integer, Integer>(); // 创建HashMap对象
|
||||
hm.put(1, sp.load(this, R.raw.musictest, 1)); // 加载声音文件musictest并且设置为1号声音放入hm中
|
||||
}
|
||||
|
||||
// 播放声音的方法
|
||||
public void playSound(int sound, int loop) { // 获取AudioManager引用
|
||||
AudioManager am = (AudioManager) this
|
||||
.getSystemService(Context.AUDIO_SERVICE);
|
||||
// 获取当前音量
|
||||
float streamVolumeCurrent = am
|
||||
.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
// 获取系统最大音量
|
||||
float streamVolumeMax = am
|
||||
.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
// 计算得到播放音量
|
||||
float volume = streamVolumeCurrent / streamVolumeMax;
|
||||
// 调用SoundPool的play方法来播放声音文件
|
||||
currStreamId = sp.play(hm.get(sound), volume, volume, 1, loop, 1.0f);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user