@@ -28,6 +28,7 @@ public class MainActivity extends AppCompatActivity implements MediaPlayer.OnPre
28
28
VisualizerView visualizerView ;
29
29
MediaPlayer mediaPlayer ;
30
30
Random random = new Random ();
31
+ String mp3DataUrl = "http://www.tingge123.com/mp3/2015-01-29/1422490375.mp3" ;
31
32
32
33
@ Override
33
34
protected void onCreate (Bundle savedInstanceState ) {
@@ -37,11 +38,8 @@ protected void onCreate(Bundle savedInstanceState) {
37
38
final Button button = (Button ) findViewById (R .id .btn_play );
38
39
mediaPlayer = new MediaPlayer ();
39
40
40
- // visualizerView = (VisualizerView) findViewById(R.id.wavView);
41
-
42
41
initVisual (relativeLayout );
43
42
44
-
45
43
if (button != null ) {
46
44
button .setOnClickListener (new View .OnClickListener () {
47
45
@ Override
@@ -56,7 +54,7 @@ public void onClick(View view) {
56
54
mediaPlayer .reset ();
57
55
mediaPlayer .setAudioStreamType (AudioManager .STREAM_MUSIC );
58
56
try {
59
- mediaPlayer .setDataSource ("http://www.tingge123.com/mp3/2015-01-29/1422490375.mp3" );
57
+ mediaPlayer .setDataSource (mp3DataUrl );
60
58
} catch (IOException e ) {
61
59
e .printStackTrace ();
62
60
}
@@ -128,33 +126,33 @@ private void init() {
128
126
int color = Color .rgb (random .nextInt (255 ), random .nextInt (255 ), random .nextInt (255 ));
129
127
mForePaint .setColor (color );
130
128
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();
158
156
}
159
157
160
158
0 commit comments