Skip to content

Commit 8fdade8

Browse files
committed
Show simple visualizer.
1 parent 60dd0e4 commit 8fdade8

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

app/src/main/java/com/sackcentury/androidmusicwave/MainActivity.java

+29-31
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class MainActivity extends AppCompatActivity implements MediaPlayer.OnPre
2828
VisualizerView visualizerView;
2929
MediaPlayer mediaPlayer;
3030
Random random = new Random();
31+
String mp3DataUrl = "http://www.tingge123.com/mp3/2015-01-29/1422490375.mp3";
3132

3233
@Override
3334
protected void onCreate(Bundle savedInstanceState) {
@@ -37,11 +38,8 @@ protected void onCreate(Bundle savedInstanceState) {
3738
final Button button = (Button) findViewById(R.id.btn_play);
3839
mediaPlayer = new MediaPlayer();
3940

40-
// visualizerView = (VisualizerView) findViewById(R.id.wavView);
41-
4241
initVisual(relativeLayout);
4342

44-
4543
if (button != null) {
4644
button.setOnClickListener(new View.OnClickListener() {
4745
@Override
@@ -56,7 +54,7 @@ public void onClick(View view) {
5654
mediaPlayer.reset();
5755
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
5856
try {
59-
mediaPlayer.setDataSource("http://www.tingge123.com/mp3/2015-01-29/1422490375.mp3");
57+
mediaPlayer.setDataSource(mp3DataUrl);
6058
} catch (IOException e) {
6159
e.printStackTrace();
6260
}
@@ -128,33 +126,33 @@ private void init() {
128126
int color = Color.rgb(random.nextInt(255), random.nextInt(255), random.nextInt(255));
129127
mForePaint.setColor(color);
130128

131-
new Thread(new Runnable() {
132-
@Override
133-
public void run() {
134-
while (true) {
135-
if (mPoints != null) {
136-
for (int i = 0; i < mSpectrumNum; i++) {
137-
float height = mPoints[i * 4 + 3] + 2;
138-
if (height < getHeight() - 100) {
139-
mPoints[i * 4 + 3] = height;
140-
}
141-
}
142-
runOnUiThread(new Runnable() {
143-
@Override
144-
public void run() {
145-
invalidate();
146-
}
147-
});
148-
}
149-
try {
150-
Thread.sleep(10);
151-
} catch (InterruptedException e) {
152-
e.printStackTrace();
153-
}
154-
}
155-
156-
}
157-
}).start();
129+
// new Thread(new Runnable() {
130+
// @Override
131+
// public void run() {
132+
// while (true) {
133+
// if (mPoints != null) {
134+
// for (int i = 0; i < mSpectrumNum; i++) {
135+
// float height = mPoints[i * 4 + 3] + 2;
136+
// if (height < getHeight() - 100) {
137+
// mPoints[i * 4 + 3] = height;
138+
// }
139+
// }
140+
// runOnUiThread(new Runnable() {
141+
// @Override
142+
// public void run() {
143+
// invalidate();
144+
// }
145+
// });
146+
// }
147+
// try {
148+
// Thread.sleep(10);
149+
// } catch (InterruptedException e) {
150+
// e.printStackTrace();
151+
// }
152+
// }
153+
//
154+
// }
155+
// }).start();
158156
}
159157

160158

0 commit comments

Comments
 (0)