반응형

미니 플젝으로 피아노 만들어보았다.



HorizontalScrollview에 FrameLayout을 얹고 white keyboard, black keyboard를 배치하였다.


피아노 키에 대해서 잘 모르는 관계로... 저 첫시작 도가 c1인지 c2인지.. 잘 모르겠다..


피아노 음은 일일이 음을 따올수가 없어서 어플 다운받아서 디컴파일하여 음을 가져왔다.


https://apkpure.com/ << 컴퓨터에서 apk파일 다운로드 하는 사이트


디컴파일 하는 방법을 이것 저것 다 시도해보다가


https://www.youtube.com/watch?v=VLsJETb3m4M << 유튜브의 이 영상을 보고 많은 도움을 얻었다.


http://www.javadecompilers.com/ << 영상에서 소개해주는 디컴파일 사이트


(참고로..

평소 음원 확장자를 .mp4나 wav파일만 알고 있어서 이걸로 찾으려니 안찾아졌다..

디컴파일하여 얻은 음원의 확장자는 ogg였다.

ogg란?

------------------------------------------------------------------------------------------------------------------------------------------------

Ogg(오그)는 멀티미디어 컨테이너 포맷이다. 특허권으로 보호되지 않는 오픈 표준 파일 형식으로 멀티미디어 비트스트림을 효율적으로 전송하고 처리할 수 있게 하기 위해 Xiph.Org 재단에서 개발한 것이다.


출처 - 위키백과

------------------------------------------------------------------------------------------------------------------------------------------------

지식 하나 더 얻어간다@_@)


프로젝트 폴더\res폴더에 디컴파일하여 얻은 음원을 raw폴더를 생성하여 여기에 넣어준다.


레이아웃 가로모드 설정하기 위해서 프로젝트 폴더 경로를 따라 res 폴더로 들어가서 한개로 되어있는 layout폴더를



이렇게 두개로 나눠준다.(각각 폴더 안에 xml파일 포함되어 있음.)


결과적으로 안드로이드 스튜디오 가서 폴더를 확인해보면 layout폴더 밑에 actibvity_main(2)라고 설정 되어있는것을 볼 수 있다.




다음은 piano xml, java코드이다.


< activity_main.xml> 

버튼이 많은 관계로 엄청 길다...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="10"
    tools:context=".MainActivity">
 
    <HorizontalScrollView
        android:id="@+id/sv"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="10">
 
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
 
            <!--White KeyBoard-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">
 
                <ImageButton
                    android:id="@+id/do1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/re1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/mi1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/pa1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/sol1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/ra1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/si1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <!--///////////////////////-->
                <ImageButton
                    android:id="@+id/do2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/re2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/mi2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/pa2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/sol2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/ra2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/si2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <!--///////////////////////-->
 
                <ImageButton
                    android:id="@+id/do3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/re3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/mi3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/pa3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/sol3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/ra3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/si3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <!--///////////////////////-->
                <ImageButton
                    android:id="@+id/do4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/re4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/mi4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/pa4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/sol4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/ra4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
 
                <ImageButton
                    android:id="@+id/si4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="clickedKeyboard"
                    android:padding="0dp"
                    app:srcCompat="@drawable/whitebutton" />
            </LinearLayout>
 
            <!--Black KeyBoard-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">
 
                <ImageButton
                    android:id="@+id/doShap1"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="95dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/reShap1"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="60dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/paShap1"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="190dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/solShap1"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="60dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/raShap1"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="60dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <!--///////////////////////-->
 
                <ImageButton
                    android:id="@+id/doShap2"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="190dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/reShap2"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="69dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/paShap2"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="185dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/solShap2"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="60dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/raShap2"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="60dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <!--///////////////////////-->
 
                <ImageButton
                    android:id="@+id/doShap3"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="190dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/reShap3"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="69dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/paShap3"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="185dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/solShap3"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="60dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/raShap3"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="60dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <!--///////////////////////-->
 
                <ImageButton
                    android:id="@+id/doShap4"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="190dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/reShap4"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="69dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/paShap4"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="185dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/solShap4"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="60dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
 
                <ImageButton
                    android:id="@+id/raShap4"
                    android:layout_width="wrap_content"
                    android:layout_height="180dp"
                    android:layout_marginLeft="60dp"
                    android:onClick="blackKeyBoardClicked"
                    android:padding="0dp"
                    app:srcCompat="@drawable/blackbutton" />
            </LinearLayout>
        </FrameLayout>
    </HorizontalScrollView>
</LinearLayout>
cs


<MainActivity.java>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
package com.example.sh.piano;
 
import android.content.pm.ActivityInfo;
import android.media.AudioManager;
import android.media.SoundPool;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.HorizontalScrollView;
import android.widget.ImageButton;
 
 
public class MainActivity extends AppCompatActivity {
 
 
    SoundPool pool;
    //White keyBoard
    int do1, re1, mi1, pa1, sol1, ra1, si1;
    int do2, re2, mi2, pa2, sol2, ra2, si2;
    int do3, re3, mi3, pa3, sol3, ra3, si3;
    int do4, re4, mi4, pa4, sol4, ra4, si4;
    //Black KeyBoard
    int doShap1, reShap1, paShap1, solShap1, raShap1;
    int doShap2, reShap2, paShap2, solShap2, raShap2;
    int doShap3, reShap3, paShap3, solShap3, raShap3;
    int doShap4, reShap4, paShap4, solShap4, raShap4;
 
    private float x, y;
 
    ImageButton doBtn1, reBtn1, miBtn1, paBtn1, solBtn1, raBtn1, siBtn1;
    ImageButton doBtn2, reBtn2, miBtn2, paBtn2, solBtn2, raBtn2, siBtn2;
    ImageButton doBtn3, reBtn3, miBtn3, paBtn3, solBtn3, raBtn3, siBtn3;
    ImageButton doBtn4, reBtn4, miBtn4, paBtn4, solBtn4, raBtn4, siBtn4;
 
 
    private HorizontalScrollView sv;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
 
        setContentView(R.layout.activity_main);
 
        getXmlId();
        loadMusic();
    }
    public void controlScroll(View view) {
        View.OnTouchListener touchListener = new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                final int action = motionEvent.getAction();
                switch (action & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_DOWN :
                        // 처음 터치가 눌러졌을 때
                        // TodoList : 해당 건반만 소리 나게 설정
 
                        break;
                    case MotionEvent.ACTION_MOVE:
                        // 터치가 눌린 상태에서 움직일 때
                        // "도레미파솔라시도"처럼 음 소리나게
                        // 스크롤뷰 움직이지 못하게 막기
 
                        break;
                    case MotionEvent.ACTION_UP :
                        // 터치가 떼어졌을 때
                        // 소리안남
 
                        break;
                    case MotionEvent.ACTION_POINTER_DOWN:
                        // 터치가 두 개 이상 && 눌러졌을 때
 
                        // TodoList : 스크롤 움직이기
                        final int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
                        // x = getX(pointerIndex);
                        // y = getY(pointerIndex);
                        break;
                }
                return true;
            }
        };
    }
 
    public void clickedKeyboard(View view) {
        switch (view.getId()) {
            //White KeyBoard Id
            case R.id.do1:
                pool.play(do1, 11001);
                break;
            case R.id.re1:
                pool.play(re1, 11001);
                break;
            case R.id.mi1:
                pool.play(mi1, 11001);
                break;
            case R.id.pa1:
                pool.play(pa1, 11001);
                break;
            case R.id.sol1:
                pool.play(sol1, 11001);
                break;
            case R.id.ra1:
                pool.play(ra1, 11001);
                break;
            case R.id.si1:
                pool.play(si1, 11001);
                break;
            ////////////////////////////////////////////////////////////
            case R.id.do2:
                pool.play(do2, 11001);
                break;
            case R.id.re2:
                pool.play(re2, 11001);
                break;
            case R.id.mi2:
                pool.play(mi2, 11001);
                break;
            case R.id.pa2:
                pool.play(pa2, 11001);
                break;
            case R.id.sol2:
                pool.play(sol2, 11001);
                break;
            case R.id.ra2:
                pool.play(ra2, 11001);
                break;
            case R.id.si2:
                pool.play(si2, 11001);
                break;
            ////////////////////////////////////////////////////////////
            case R.id.do3:
                pool.play(do3, 11001);
                break;
            case R.id.re3:
                pool.play(re3, 11001);
                break;
            case R.id.mi3:
                pool.play(mi3, 11001);
                break;
            case R.id.pa3:
                pool.play(pa3, 11001);
                break;
            case R.id.sol3:
                pool.play(sol3, 11001);
                break;
            case R.id.ra3:
                pool.play(ra3, 11001);
                break;
            case R.id.si3:
                pool.play(si3, 11001);
                break;
            ////////////////////////////////////////////////////////////
            case R.id.do4:
                pool.play(do4, 11001);
                break;
            case R.id.re4:
                pool.play(re4, 11001);
                break;
            case R.id.mi4:
                pool.play(mi4, 11001);
                break;
            case R.id.pa4:
                pool.play(pa4, 11001);
                break;
            case R.id.sol4:
                pool.play(sol4, 11001);
                break;
            case R.id.ra4:
                pool.play(ra4, 11001);
                break;
            case R.id.si4:
                pool.play(si4, 11001);
                break;
        }
    }
 
    public void blackKeyBoardClicked(View view) {
        switch (view.getId()) {
            //Black KeyBoard Id
            case R.id.doShap1:
                pool.play(doShap1, 11001);
                break;
            case R.id.reShap1:
                pool.play(reShap1, 11001);
                break;
            case R.id.paShap1:
                pool.play(paShap1, 11001);
                break;
            case R.id.solShap1:
                pool.play(solShap1, 11001);
                break;
            case R.id.raShap1:
                pool.play(raShap1, 11001);
                break;
            ////////////////////////////////////////////////////////////
            case R.id.doShap2:
                pool.play(doShap2, 11001);
                break;
            case R.id.reShap2:
                pool.play(reShap2, 11001);
                break;
            case R.id.paShap2:
                pool.play(paShap2, 11001);
                break;
            case R.id.solShap2:
                pool.play(solShap2, 11001);
                break;
            case R.id.raShap2:
                pool.play(raShap2, 11001);
                break;
            ////////////////////////////////////////////////////////////
            case R.id.doShap3:
                pool.play(doShap3, 11001);
                break;
            case R.id.reShap3:
                pool.play(reShap3, 11001);
                break;
            case R.id.paShap3:
                pool.play(paShap3, 11001);
                break;
            case R.id.solShap3:
                pool.play(solShap3, 11001);
                break;
            case R.id.raShap3:
                pool.play(raShap3, 11001);
                break;
            ////////////////////////////////////////////////////////////
            case R.id.doShap4:
                pool.play(doShap4, 11001);
                break;
            case R.id.reShap4:
                pool.play(reShap4, 11001);
                break;
            case R.id.paShap4:
                pool.play(paShap4, 11001);
                break;
            case R.id.solShap4:
                pool.play(solShap4, 11001);
                break;
            case R.id.raShap4:
                pool.play(raShap4, 11001);
                break;
        }
    }
 
    public void getXmlId() {
        sv = findViewById(R.id.sv);
        doBtn1 = findViewById(R.id.do1);
        reBtn1 = findViewById(R.id.re1);
        miBtn1 = findViewById(R.id.mi1);
        paBtn1 = findViewById(R.id.pa1);
        solBtn1 = findViewById(R.id.sol1);
        raBtn1 = findViewById(R.id.ra1);
        siBtn1 = findViewById(R.id.si1);
        ///
        doBtn2 = findViewById(R.id.do2);
        reBtn2 = findViewById(R.id.re2);
        miBtn2 = findViewById(R.id.mi2);
        paBtn2 = findViewById(R.id.pa2);
        solBtn2 = findViewById(R.id.sol2);
        raBtn2 = findViewById(R.id.ra2);
        siBtn2 = findViewById(R.id.si2);
        ///
        doBtn3 = findViewById(R.id.do3);
        reBtn3 = findViewById(R.id.re3);
        miBtn3 = findViewById(R.id.mi3);
        paBtn3 = findViewById(R.id.pa3);
        solBtn3 = findViewById(R.id.sol3);
        raBtn3 = findViewById(R.id.ra3);
        siBtn3 = findViewById(R.id.si3);
        ///
        doBtn4 = findViewById(R.id.do4);
        reBtn4 = findViewById(R.id.re4);
        miBtn4 = findViewById(R.id.mi4);
        paBtn4 = findViewById(R.id.pa4);
        solBtn4 = findViewById(R.id.sol4);
        raBtn4 = findViewById(R.id.ra4);
        siBtn4 = findViewById(R.id.si4);
    }
 
    public void loadMusic() {
        pool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
 
        //WhiteKeyBoard Soundpool
        do1 = pool.load(this, R.raw.do1, 1);
        re1 = pool.load(this, R.raw.re1, 1);
        mi1 = pool.load(this, R.raw.mi1, 1);
        pa1 = pool.load(this, R.raw.pa1, 1);
        sol1 = pool.load(this, R.raw.sol1, 1);
        ra1 = pool.load(this, R.raw.ra1, 1);
        si1 = pool.load(this, R.raw.si1, 1);
        /////////////////
        do2 = pool.load(this, R.raw.do2, 1);
        re2 = pool.load(this, R.raw.re2, 1);
        mi2 = pool.load(this, R.raw.mi2, 1);
        pa2 = pool.load(this, R.raw.pa2, 1);
        sol2 = pool.load(this, R.raw.sol2, 1);
        ra2 = pool.load(this, R.raw.ra2, 1);
        si2 = pool.load(this, R.raw.si2, 1);
        /////////////////
        do3 = pool.load(this, R.raw.do3, 1);
        re3 = pool.load(this, R.raw.re3, 1);
        mi3 = pool.load(this, R.raw.mi3, 1);
        pa3 = pool.load(this, R.raw.pa3, 1);
        sol3 = pool.load(this, R.raw.sol3, 1);
        ra3 = pool.load(this, R.raw.ra3, 1);
        si3 = pool.load(this, R.raw.si3, 1);
        /////////////////
        do4 = pool.load(this, R.raw.do4, 1);
        re4 = pool.load(this, R.raw.re4, 1);
        mi4 = pool.load(this, R.raw.mi4, 1);
        pa4 = pool.load(this, R.raw.pa4, 1);
        sol4 = pool.load(this, R.raw.sol4, 1);
        ra4 = pool.load(this, R.raw.ra4, 1);
        si4 = pool.load(this, R.raw.si4, 1);
 
 
        //BlackKeyBoard Soundpool
        doShap1 = pool.load(this, R.raw.doshap1, 1);
        reShap1 = pool.load(this, R.raw.reshap1, 1);
        paShap1 = pool.load(this, R.raw.pashap1, 1);
        solShap1 = pool.load(this, R.raw.solshap1, 1);
        raShap1 = pool.load(this, R.raw.rashap1, 1);
        /////////////////
        doShap2 = pool.load(this, R.raw.doshap2, 1);
        reShap2 = pool.load(this, R.raw.reshap2, 1);
        paShap2 = pool.load(this, R.raw.pashap2, 1);
        solShap2 = pool.load(this, R.raw.solshap2, 1);
        raShap2 = pool.load(this, R.raw.rashap2, 1);
        /////////////////
        doShap3 = pool.load(this, R.raw.doshap3, 1);
        reShap3 = pool.load(this, R.raw.reshap3, 1);
        paShap3 = pool.load(this, R.raw.pashap3, 1);
        solShap3 = pool.load(this, R.raw.solshap3, 1);
        raShap3 = pool.load(this, R.raw.rashap3, 1);
        /////////////////
        doShap4 = pool.load(this, R.raw.doshap4, 1);
        reShap4 = pool.load(this, R.raw.reshap4, 1);
        paShap4 = pool.load(this, R.raw.pashap4, 1);
        solShap4 = pool.load(this, R.raw.solshap4, 1);
        raShap4 = pool.load(this, R.raw.rashap4, 1);
 
    }
}

cs



마지막으로 구현한 피아노로 연주하는 동영상..ㅎ



반응형

'Android' 카테고리의 다른 글

[Android] 전체화면 전환  (0) 2018.08.17
[Android] Open API 사용해서 부산 버스 어플 만들기  (5) 2018.08.17

+ Recent posts