Skip to content

Commit cf54c1f

Browse files
committed
BOOP/BLOOP.
1 parent eb1c612 commit cf54c1f

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed

BaseGameUtils/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:1.3.1'
9+
classpath 'com.android.tools.build:gradle:2.2.3'
1010
}
1111
}
1212

app/src/main/java/website/bloop/app/BloopActivity.java

+7
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public class BloopActivity extends AppCompatActivity implements OnMapReadyCallba
9898

9999
private GoogleApiClient mGoogleApiClient;
100100
private boolean mAreControlsVisible;
101+
private BloopSoundPlayer mBloopSoundPlayer;
101102

102103
@Override
103104
protected void onCreate(Bundle savedInstanceState) {
@@ -143,6 +144,9 @@ protected void onCreate(Bundle savedInstanceState) {
143144
setSupportActionBar(mToolbar);
144145

145146
mGoogleApiClient = BloopApplication.getInstance().getClient();
147+
148+
// init sounds
149+
mBloopSoundPlayer = new BloopSoundPlayer(this);
146150
}
147151

148152
private void showHideControls() {
@@ -182,6 +186,8 @@ private void captureFlag() {
182186
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
183187
if (response.code() >= 200 && response.code() < 400) {
184188
// flag capture success!
189+
mBloopSoundPlayer.bloop();
190+
185191
final AlertDialog.Builder builder = new AlertDialog.Builder(self);
186192
builder
187193
.setTitle(String.format(getString(R.string.you_captured_x_flag_format_string), requestedFlagOwner))
@@ -440,6 +446,7 @@ public void run() {
440446
private void bloop() {
441447
mSonarView.bloop();
442448
//TODO: play sound
449+
mBloopSoundPlayer.boop();
443450

444451
mLastBloopTime = System.currentTimeMillis();
445452
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package website.bloop.app;
2+
3+
import android.content.Context;
4+
import android.media.AudioAttributes;
5+
import android.media.AudioManager;
6+
import android.media.SoundPool;
7+
import android.os.Build;
8+
9+
public class BloopSoundPlayer {
10+
private final Context mContext;
11+
12+
private SoundPool mSoundPool;
13+
private final int mBoop;
14+
private final int mBloop;
15+
16+
private static final float VOLUME = 1f;
17+
private static final int PRIORITY = 1;
18+
private static final int REPEATS = 0;
19+
private static final float PLAYBACK_SPEED = 1f;
20+
21+
public BloopSoundPlayer(Context context) {
22+
mContext = context;
23+
24+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
25+
AudioAttributes soundAttributes = new AudioAttributes.Builder()
26+
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
27+
.setUsage(AudioAttributes.USAGE_GAME)
28+
.build();
29+
30+
mSoundPool = new SoundPool.Builder()
31+
.setMaxStreams(6)
32+
.setAudioAttributes(soundAttributes)
33+
.build();
34+
} else {
35+
mSoundPool = new SoundPool(6, AudioManager.STREAM_MUSIC, 100);
36+
}
37+
38+
mBoop = mSoundPool.load(mContext, R.raw.boop, 1);
39+
mBloop = mSoundPool.load(mContext, R.raw.bloop, 1);
40+
}
41+
42+
public void boop() {
43+
mSoundPool.play(mBoop, VOLUME, VOLUME, PRIORITY, REPEATS, PLAYBACK_SPEED);
44+
}
45+
46+
public void bloop() {
47+
mSoundPool.play(mBloop, VOLUME, VOLUME, PRIORITY, REPEATS, PLAYBACK_SPEED);
48+
}
49+
}

app/src/main/res/raw/bloop.wav

920 KB
Binary file not shown.

app/src/main/res/raw/boop.wav

230 KB
Binary file not shown.

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
mavenCentral()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:2.2.2'
9+
classpath 'com.android.tools.build:gradle:2.2.3'
1010

1111
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
1212
classpath 'me.tatarka:gradle-retrolambda:3.3.1'

0 commit comments

Comments
 (0)