Tja dann schaut euch mal mein Durcheinander an
Über Kritik wäre ich sehr dankbar (bin schließlich totaler Anfänger), aber dann bitte mit kurzer Erklärung!
Thx
Hier auch nochmals als
.java Datei !
1package de.hit.test;
2
3import android.app.Activity;
4import android.content.Context;
5import android.content.res.AssetFileDescriptor;
6import android.media.AudioManager;
7import android.media.SoundPool;
8import android.os.Bundle;
9import android.view.View;
10import android.view.View.OnClickListener;
11import android.widget.Button;
12import android.widget.EditText;
13
14public class EingabeActivity extends Activity implements OnClickListener {
15 /** Called when the activity is first created. */
16 int sprinten = 0;
17 int gehens = 0;
18 int ziel = 0;
19 int zehn = 0;
20 int vier = 0;
21 int zwei = 0;
22 SoundPool soundPool;
23 AudioManager audioManager;
24 private Button button;
25 private Button exit;
26
27 @Override
28 public void onCreate(Bundle savedInstanceState) {
29 super.onCreate(savedInstanceState);
30 setContentView(R.layout.main);
31
32 button = (Button) findViewById(R.id.button);
33 button.setOnClickListener(this);
34 exit = (Button) findViewById(R.id.exit);
35 exit.setOnClickListener(this);
36
37 soundPool = new SoundPool( 5, AudioManager.STREAM_MUSIC, 0);
38 audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
39
40 try {
41 AssetFileDescriptor descriptor = getAssets().openFd( "sprint.wav" );
42 sprinten = soundPool.load( descriptor, 1 );
43
44 AssetFileDescriptor descriptor2 = getAssets().openFd( "ziel.wav" );
45 ziel = soundPool.load( descriptor2, 1 );
46
47 AssetFileDescriptor descriptor3 = getAssets().openFd( "zehn.wav" );
48 zehn = soundPool.load( descriptor3, 1 );
49
50 AssetFileDescriptor descriptor4 = getAssets().openFd( "vier.wav" );
51 vier = soundPool.load( descriptor4, 1 );
52
53 AssetFileDescriptor descriptor5 = getAssets().openFd( "zwei.wav" );
54 zwei = soundPool.load( descriptor5, 1 );
55
56 AssetFileDescriptor descriptor6 = getAssets().openFd( "gehen.wav" );
57 gehens = soundPool.load( descriptor6, 1 );
58 }
59 catch( Exception ex ) {
60 //Log.d( "Sound Sample", "couldn't load sound 'shot.wav'" );
61 throw new RuntimeException( ex );
62 }
63 }
64
65
66 public void onClick(View v) {
67 //Variable hits für die Anzahl der Hits
68 EditText hitsvar = (EditText) findViewById(R.id.hits);
69 String hitsvar2 = hitsvar.getText().toString();
70 int hits = Integer.valueOf( hitsvar2 ).intValue();
71 //Variable sprint für die Zeit zum sprinten
72 EditText sprintvar = (EditText) findViewById(R.id.sprint);
73 String sprintvar2 = sprintvar.getText().toString();
74 int sprint = Integer.valueOf( sprintvar2 ).intValue();
75 //Variable gehen für die Zeit zum gehen
76 EditText gehenvar = (EditText) findViewById(R.id.gehen);
77 String gehenvar2 = gehenvar.getText().toString();
78 int gehen = Integer.valueOf( gehenvar2 ).intValue();
79 //Variable für Counter
80 int counter = 0;
81
82
83
84 if (v == button) {
85 int volume = audioManager.getStreamVolume( AudioManager.STREAM_MUSIC );
86 try {
87 Thread.sleep(5000);
88 } catch (InterruptedException e) {
89 // TODO Auto-generated catch block
90 e.printStackTrace();
91 }
92
93 while (counter++ < hits) {
94 //Schleife für sprint!
95 soundPool.play(sprinten, volume, volume, 1, 0, 1);
96 try {
97 Thread.sleep((sprint-10)*1000);
98 } catch (InterruptedException e) {
99 // TODO Auto-generated catch block
100 e.printStackTrace();
101 }
102 soundPool.play(zehn, volume, volume, 1, 0, 1);
103
104 try {
105 Thread.sleep(6000);
106 } catch (InterruptedException e) {
107 // TODO Auto-generated catch block
108 e.printStackTrace();
109 }
110 soundPool.play(vier, volume, volume, 1, 0, 1);
111
112 try {
113 Thread.sleep(2000);
114 } catch (InterruptedException e) {
115 // TODO Auto-generated catch block
116 e.printStackTrace();
117 }
118 soundPool.play(zwei, volume, volume, 1, 0, 1);
119
120 try {
121 Thread.sleep(2000);
122 } catch (InterruptedException e) {
123 // TODO Auto-generated catch block
124 e.printStackTrace();
125 }
126
127
128 if (counter == hits) {
129 soundPool.play(ziel, volume, volume, 1, 0, 1);
130 } else {
131 //Schleife für gehen!
132 soundPool.play(gehens, volume, volume, 1, 0, 1);
133 try {
134 Thread.sleep((gehen-10)*1000);
135 } catch (InterruptedException e) {
136 // TODO Auto-generated catch block
137 e.printStackTrace();
138 }
139 soundPool.play(zehn, volume, volume, 1, 0, 1);
140
141 try {
142 Thread.sleep(6000);
143 } catch (InterruptedException e) {
144 // TODO Auto-generated catch block
145 e.printStackTrace();
146 }
147 soundPool.play(vier, volume, volume, 1, 0, 1);
148
149 try {
150 Thread.sleep(2000);
151 } catch (InterruptedException e) {
152 // TODO Auto-generated catch block
153 e.printStackTrace();
154 }
155 soundPool.play(zwei, volume, volume, 1, 0, 1);
156
157 try {
158 Thread.sleep(2000);
159 } catch (InterruptedException e) {
160 // TODO Auto-generated catch block
161 e.printStackTrace();
162 }
163 }
164 }
165 }
166
167 if (v == exit) {
168 System.exit(0);
169 }
170 }
171}
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.