質問編集履歴
1
コードの修正、誤字脱字の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,10 +16,324 @@
|
|
16
16
|
|
17
17
|
### 該当のソースコード
|
18
18
|
|
19
|
-
|
19
|
+
AndroidManifest.xml
|
20
|
+
|
21
|
+
```xml
|
22
|
+
|
23
|
+
<?xml version="1.0" encoding="utf-8"?>
|
24
|
+
|
25
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
26
|
+
|
27
|
+
package="com.android_test.babesnaky">
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
32
|
+
|
33
|
+
<application
|
34
|
+
|
35
|
+
android:allowBackup="true"
|
36
|
+
|
37
|
+
android:icon="@mipmap/ic_launcher"
|
38
|
+
|
39
|
+
android:label="@string/app_name"
|
40
|
+
|
41
|
+
android:roundIcon="@mipmap/ic_launcher_round"
|
42
|
+
|
43
|
+
android:supportsRtl="true"
|
44
|
+
|
45
|
+
android:theme="@style/AppTheme">
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<!-- <activity android:name=".FutatsumeActivity"></activity> -->
|
50
|
+
|
51
|
+
<!-- <activity android:name=".MittsumeActivity"></activity> -->
|
52
|
+
|
53
|
+
<activity android:name=".MusicActivity">
|
54
|
+
|
55
|
+
<intent-filter>
|
56
|
+
|
57
|
+
<action android:name="android.intent.action.MAIN" />
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
62
|
+
|
63
|
+
</intent-filter>
|
64
|
+
|
65
|
+
</activity>
|
66
|
+
|
67
|
+
<!--<activity android:name=".YottsumeActivity" />-->
|
68
|
+
|
69
|
+
<!--<activity android:name=".MusicActivity"></activity>-->
|
70
|
+
|
71
|
+
</application>
|
72
|
+
|
73
|
+
</manifest>
|
74
|
+
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
activity_music.xml
|
80
|
+
|
81
|
+
```xml
|
82
|
+
|
83
|
+
<?xml version="1.0" encoding="utf-8"?>
|
84
|
+
|
85
|
+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
86
|
+
|
87
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
88
|
+
|
89
|
+
xmlns:tools="http://schemas.android.com/tools"
|
90
|
+
|
91
|
+
android:layout_width="match_parent"
|
92
|
+
|
93
|
+
android:layout_height="match_parent"
|
94
|
+
|
95
|
+
tools:context=".MusicActivity">
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
<LinearLayout
|
100
|
+
|
101
|
+
android:id="@+id/linearLayout"
|
102
|
+
|
103
|
+
android:layout_width="361dp"
|
104
|
+
|
105
|
+
android:layout_height="59dp"
|
106
|
+
|
107
|
+
android:layout_alignParentTop="true"
|
108
|
+
|
109
|
+
android:layout_marginStart="8dp"
|
110
|
+
|
111
|
+
android:layout_marginLeft="8dp"
|
112
|
+
|
113
|
+
android:layout_marginTop="12dp"
|
114
|
+
|
115
|
+
android:layout_marginEnd="8dp"
|
116
|
+
|
117
|
+
android:layout_marginRight="8dp"
|
118
|
+
|
119
|
+
android:layout_marginBottom="8dp"
|
120
|
+
|
121
|
+
android:gravity="start"
|
122
|
+
|
123
|
+
android:orientation="horizontal"
|
124
|
+
|
125
|
+
app:layout_constraintBottom_toTopOf="@+id/linearLayout3"
|
126
|
+
|
127
|
+
app:layout_constraintEnd_toEndOf="parent"
|
128
|
+
|
129
|
+
app:layout_constraintStart_toStartOf="parent"
|
130
|
+
|
131
|
+
app:layout_constraintTop_toTopOf="parent">
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
<TextView
|
136
|
+
|
137
|
+
android:id="@+id/title"
|
138
|
+
|
139
|
+
android:layout_width="340dp"
|
140
|
+
|
141
|
+
android:layout_height="wrap_content"
|
142
|
+
|
143
|
+
android:layout_marginStart="8dp"
|
144
|
+
|
145
|
+
android:layout_marginLeft="8dp"
|
146
|
+
|
147
|
+
android:layout_marginEnd="8dp"
|
148
|
+
|
149
|
+
android:layout_marginRight="8dp"
|
150
|
+
|
151
|
+
android:layout_marginBottom="8dp"
|
152
|
+
|
153
|
+
android:layout_weight="1"
|
154
|
+
|
155
|
+
android:text="タイトル"
|
156
|
+
|
157
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
158
|
+
|
159
|
+
app:layout_constraintEnd_toEndOf="parent"
|
160
|
+
|
161
|
+
app:layout_constraintStart_toStartOf="parent"
|
162
|
+
|
163
|
+
app:layout_constraintTop_toTopOf="parent"
|
164
|
+
|
165
|
+
app:layout_constraintVertical_bias="0.0" />
|
166
|
+
|
167
|
+
</LinearLayout>
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
<LinearLayout
|
172
|
+
|
173
|
+
android:id="@+id/linearLayout3"
|
174
|
+
|
175
|
+
android:layout_width="368dp"
|
176
|
+
|
177
|
+
android:layout_height="53dp"
|
178
|
+
|
179
|
+
android:layout_below="@+id/linearLayout"
|
180
|
+
|
181
|
+
android:layout_marginStart="8dp"
|
182
|
+
|
183
|
+
android:layout_marginLeft="8dp"
|
184
|
+
|
185
|
+
android:layout_marginTop="24dp"
|
186
|
+
|
187
|
+
android:layout_marginEnd="8dp"
|
188
|
+
|
189
|
+
android:layout_marginRight="8dp"
|
190
|
+
|
191
|
+
android:orientation="horizontal"
|
192
|
+
|
193
|
+
app:layout_constraintBottom_toTopOf="@+id/linearLayout4"
|
194
|
+
|
195
|
+
app:layout_constraintEnd_toEndOf="parent"
|
196
|
+
|
197
|
+
app:layout_constraintStart_toStartOf="parent">
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
<SeekBar
|
202
|
+
|
203
|
+
android:id="@+id/positionBar"
|
204
|
+
|
205
|
+
android:layout_width="wrap_content"
|
206
|
+
|
207
|
+
android:layout_height="wrap_content"
|
208
|
+
|
209
|
+
android:layout_weight="1" />
|
210
|
+
|
211
|
+
</LinearLayout>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
<LinearLayout
|
216
|
+
|
217
|
+
android:id="@+id/linearLayout4"
|
218
|
+
|
219
|
+
android:layout_width="wrap_content"
|
220
|
+
|
221
|
+
android:layout_height="95dp"
|
222
|
+
|
223
|
+
android:layout_below="@+id/linearLayout3"
|
224
|
+
|
225
|
+
android:layout_alignParentBottom="true"
|
226
|
+
|
227
|
+
android:layout_marginStart="8dp"
|
228
|
+
|
229
|
+
android:layout_marginLeft="8dp"
|
230
|
+
|
231
|
+
android:layout_marginTop="33dp"
|
232
|
+
|
233
|
+
android:layout_marginEnd="8dp"
|
234
|
+
|
235
|
+
android:layout_marginRight="8dp"
|
236
|
+
|
237
|
+
android:layout_marginBottom="227dp"
|
238
|
+
|
239
|
+
android:orientation="horizontal"
|
240
|
+
|
241
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
242
|
+
|
243
|
+
app:layout_constraintEnd_toEndOf="parent"
|
244
|
+
|
245
|
+
app:layout_constraintStart_toStartOf="parent">
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
<Button
|
250
|
+
|
251
|
+
android:id="@+id/playButton"
|
252
|
+
|
253
|
+
android:layout_width="wrap_content"
|
254
|
+
|
255
|
+
android:layout_height="wrap_content"
|
256
|
+
|
257
|
+
android:layout_marginStart="104dp"
|
258
|
+
|
259
|
+
android:layout_marginLeft="104dp"
|
260
|
+
|
261
|
+
android:layout_marginTop="8dp"
|
262
|
+
|
263
|
+
android:layout_marginBottom="8dp"
|
264
|
+
|
265
|
+
android:text="再生"
|
266
|
+
|
267
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
268
|
+
|
269
|
+
app:layout_constraintStart_toStartOf="parent"
|
270
|
+
|
271
|
+
app:layout_constraintTop_toTopOf="parent"
|
272
|
+
|
273
|
+
app:layout_constraintVertical_bias="0.501" />
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
<Button
|
278
|
+
|
279
|
+
android:id="@+id/stopButton"
|
280
|
+
|
281
|
+
android:layout_width="87dp"
|
282
|
+
|
283
|
+
android:layout_height="wrap_content"
|
284
|
+
|
285
|
+
android:layout_marginTop="8dp"
|
286
|
+
|
287
|
+
android:layout_marginEnd="104dp"
|
288
|
+
|
289
|
+
android:layout_marginRight="104dp"
|
290
|
+
|
291
|
+
android:layout_marginBottom="8dp"
|
292
|
+
|
293
|
+
android:text="停止"
|
294
|
+
|
295
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
296
|
+
|
297
|
+
app:layout_constraintEnd_toEndOf="parent"
|
298
|
+
|
299
|
+
app:layout_constraintTop_toTopOf="parent"
|
300
|
+
|
301
|
+
app:layout_constraintVertical_bias="0.501" />
|
302
|
+
|
303
|
+
</LinearLayout>
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
</RelativeLayout>
|
308
|
+
|
309
|
+
```
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
MusicActivity.java
|
20
314
|
|
21
315
|
```java
|
22
316
|
|
317
|
+
package com.android_test.babesnaky;
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
import android.media.MediaPlayer;
|
322
|
+
|
323
|
+
import android.net.Uri;
|
324
|
+
|
325
|
+
import android.support.v7.app.AppCompatActivity;
|
326
|
+
|
327
|
+
import android.os.Bundle;
|
328
|
+
|
329
|
+
import android.view.View;
|
330
|
+
|
331
|
+
import android.widget.Button;
|
332
|
+
|
333
|
+
import android.widget.SeekBar;
|
334
|
+
|
335
|
+
|
336
|
+
|
23
337
|
public class MusicActivity extends AppCompatActivity implements View.OnClickListener {
|
24
338
|
|
25
339
|
|
@@ -42,6 +356,14 @@
|
|
42
356
|
|
43
357
|
setContentView(R.layout.activity_music);
|
44
358
|
|
359
|
+
Button playButton = (Button)findViewById(R.id.playButton);
|
360
|
+
|
361
|
+
Button stopButton = (Button)findViewById(R.id.stopButton);
|
362
|
+
|
363
|
+
playButton.setOnClickListener(this);
|
364
|
+
|
365
|
+
stopButton.setOnClickListener(this);
|
366
|
+
|
45
367
|
|
46
368
|
|
47
369
|
path = "https://maoudamashii.jokersounds.com/music/song/preview/song_kei_vegalost.mp3";
|
@@ -52,13 +374,77 @@
|
|
52
374
|
|
53
375
|
totalTime = mp.getDuration();
|
54
376
|
|
55
|
-
|
377
|
+
mp.start();
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
|
56
|
-
|
383
|
+
positionBar = findViewById(R.id.positionBar);
|
384
|
+
|
57
|
-
|
385
|
+
positionBar.setMax(totalTime);
|
386
|
+
|
58
|
-
|
387
|
+
positionBar.setOnSeekBarChangeListener(
|
388
|
+
|
59
|
-
|
389
|
+
new SeekBar.OnSeekBarChangeListener() {
|
390
|
+
|
60
|
-
|
391
|
+
@Override
|
392
|
+
|
61
|
-
|
393
|
+
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
394
|
+
|
395
|
+
if (fromUser) {
|
396
|
+
|
397
|
+
mp.seekTo(progress);
|
398
|
+
|
399
|
+
positionBar.setProgress(progress);
|
400
|
+
|
401
|
+
}
|
402
|
+
|
403
|
+
}
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
@Override
|
408
|
+
|
409
|
+
public void onStartTrackingTouch(SeekBar seekBar) {
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
}
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
@Override
|
418
|
+
|
419
|
+
public void onStopTrackingTouch(SeekBar seekBar) {
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
}
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
);
|
428
|
+
|
429
|
+
}
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
public void onClick(View v){
|
434
|
+
|
435
|
+
if(v.getId() == R.id.playButton){
|
436
|
+
|
437
|
+
mp.start();
|
438
|
+
|
439
|
+
}else if (v.getId() == R.id.stopButton){
|
440
|
+
|
441
|
+
mp.pause();
|
442
|
+
|
443
|
+
}
|
444
|
+
|
445
|
+
}
|
446
|
+
|
447
|
+
}
|
62
448
|
|
63
449
|
```
|
64
450
|
|
@@ -70,7 +456,7 @@
|
|
70
456
|
|
71
457
|
・<uses-permission android:name="android.permission.INTERNET" />は設定しており、
|
72
458
|
|
73
|
-
再生であれば
|
459
|
+
再生であればweb上の音声ファイルでも問題なくできます。
|
74
460
|
|
75
461
|
|
76
462
|
|