# Hilfe! es geht um Buttons und Sounds



## DrDevil_Gamer (14. Jul 2014)

Hallo erstmal,
und zwar geht es darum, ich möchte ein Soundboard für mein Handy erstellen und ich hab auch schon Buttons mit Sounds erstellt.
Code von Buttons.

```
<Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/button_bg"
                android:text="@string/Button1"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/button2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="-1dp"
                android:background="@drawable/button_bg"
                android:textColor="#FFFFFF"
                android:text="@string/Button2" />
```
Code von Sounds.

```
@Override
	public void onClick(View e) {
	if(e == b1){
		mp = MediaPlayer.create(getApplicationContext(), R.raw.doofzicke_ey);
		mp.start();
		
	}else if(e==b2){
	    mp = MediaPlayer.create(getApplicationContext(), R.raw.schrei_nicht_so);
		mp.start();
```
b1 = button1
b2 = button2

So das funktioniert auch alles.

Aber ich möchte es jetzt so haben. Wenn ich button1 und button2 hintereinander drücke dann werden ja zwei Sounds auf einmal abgespielt und das möchte ich verhindern, also so das immer nur ein Sound abgespielt werden kann.

Ich hoffe ihr könnt mir helfen.


----------



## themrdomi (14. Jul 2014)

Hi,
ich hätte es provisorisch mal so gemacht:

```
@Override
    public void onClick(View e) {
    if(e == b1){
        mp = MediaPlayer.create(getApplicationContext(), R.raw.doofzicke_ey);
        mp.stop();
        mp.start();
        
    }else if(e==b2){
        mp = MediaPlayer.create(getApplicationContext(), R.raw.schrei_nicht_so);
        mp.stop();
        mp.start();
```

Bitte überlege doch ersteinmal, was du dir überhaupt rauskopiert hast!

Lg


----------



## DrDevil_Gamer (14. Jul 2014)

Danke für die schnelle Antwort aber nach dem ich das gemacht habe, gab der LogCat folgende Fehler Meldungen aus.

```
07-07 15:21:10.850: E/logwrapper(40): executing /system/bin/e2fsck failed: No such file or directory
07-07 15:21:10.980: E/logwrapper(44): executing /system/bin/e2fsck failed: No such file or directory
07-07 15:21:18.790: E/SurfaceFlinger(52): hwcomposer module not found
07-07 15:21:22.020: E/SurfaceFlinger(52): ro.sf.lcd_density must be defined as a build property
07-07 15:21:25.930: E/AudioFlinger(55): int android::load_audio_interface(const char*, audio_hw_device_t**) couldn't load audio hw module audio.r_submix (No such file or directory)
07-07 15:21:43.850: E/memtrack(53): Couldn't load memtrack module (No such file or directory)
07-07 15:21:43.860: E/android.os.Debug(53): failed to load memtrack module: -2
07-07 15:22:13.920: E/logwrapper(293): executing /system/bin/ip failed: No such file or directory
07-07 15:22:13.990: E/logwrapper(294): executing /system/bin/ip failed: No such file or directory
07-07 15:22:14.060: E/logwrapper(295): executing /system/bin/ip failed: No such file or directory
07-07 15:22:14.100: E/logwrapper(296): executing /system/bin/ip failed: No such file or directory
07-07 15:22:14.170: E/logwrapper(297): executing /system/bin/ip failed: No such file or directory
07-07 15:22:14.220: E/logwrapper(298): executing /system/bin/ip failed: No such file or directory
07-07 15:22:14.330: E/logwrapper(299): executing /system/bin/ip failed: No such file or directory
07-07 15:22:15.010: E/EmojiFactory_jni(53): Failed to load libemoji.so: dlopen failed: library "libemoji.so" not found
07-07 15:23:50.600: E/PowerManagerService-JNI(376): Couldn't load power module (No such file or directory)
07-07 15:23:55.950: E/SurfaceFlinger(52): ro.sf.lcd_density must be defined as a build property
07-07 15:24:59.200: E/ConsumerIrService(376): Can't open consumer IR HW Module, error: -2
07-07 15:24:59.340: E/libsuspend(376): Error opening /sys/power/autosleep: No such file or directory
07-07 15:25:02.710: E/EventHub(376): could not get driver version for /dev/input/mouse0, Not a typewriter
07-07 15:25:03.080: E/EventHub(376): could not get driver version for /dev/input/mice, Not a typewriter
07-07 15:25:08.000: E/VoldConnector(376): NDC Command {1 volume list} took too long (544ms)
07-07 15:25:20.660: E/MobileDataStateTracker(376): default: Ignoring feature request because could not acquire PhoneService
07-07 15:25:20.660: E/MobileDataStateTracker(376): default: Could not enable APN type "default"
07-07 15:25:30.610: E/SELinux(376): selinux_android_restorecon:  Error restoring context for /cache/backup (No such file or directory)
07-07 15:25:30.680: E/LocalTransport(376): SELinux restorecon failed for /cache/backup
07-07 15:25:41.670: E/VoldConnector(376): NDC Command {3 volume mount /storage/sdcard} took too long (6183ms)
07-07 15:25:44.540: E/NetdConnector(376): NDC Command {1 bandwidth enable} took too long (8944ms)
07-07 15:25:46.660: E/NetdConnector(376): NDC Command {2 firewall disable} took too long (1544ms)
07-07 15:25:48.010: E/VoldConnector(376): NDC Command {4 asec list} took too long (6958ms)
07-07 15:25:49.960: E/SoundPool(427): error loading /system/media/audio/ui/Lock.ogg
07-07 15:25:50.150: E/SoundPool(427): error loading /system/media/audio/ui/Unlock.ogg
07-07 15:25:53.820: E/NetdConnector(376): NDC Command {3 bandwidth gettetherstats} took too long (5382ms)
07-07 15:25:55.580: E/NetdConnector(376): NDC Command {4 bandwidth setglobalalert 2097152} took too long (1287ms)
07-07 15:26:03.670: E/NetdConnector(376): NDC Command {5 firewall disable} took too long (1615ms)
07-07 15:26:26.900: E/LocationManagerService(376): no geocoder provider found
07-07 15:26:27.080: E/FlpHardwareProvider(376): Error hw_get_module 'flp': -2
07-07 15:26:27.150: E/FlpHardwareProvider(376): Error hw_get_module 'flp': -2
07-07 15:26:27.150: E/LocationManagerService(376): No FusedProvider found.
07-07 15:26:28.670: E/LocationManagerService(376): no geofence provider found
07-07 15:26:33.840: E/BluetoothAdapter(427): Bluetooth binder is null
07-07 15:26:33.840: E/BluetoothAdapter(427): Bluetooth binder is null
07-07 15:26:37.060: E/BluetoothAdapter(427): Bluetooth binder is null
07-07 15:26:45.060: E/BluetoothAdapter(427): Bluetooth binder is null
07-07 15:27:15.570: E/BluetoothAdapter(524): Bluetooth binder is null
07-07 15:27:18.610: E/NetdConnector(376): NDC Command {6 bandwidth gettetherstats} took too long (1816ms)
07-07 15:28:22.820: E/NetdConnector(376): NDC Command {7 bandwidth setglobalalert 2097152} took too long (900ms)
07-07 15:28:22.970: E/BluetoothAdapter(524): Bluetooth binder is null
07-07 15:28:25.580: E/BluetoothAdapter(427): Bluetooth binder is null
07-07 15:28:31.420: E/ActivityManager(376): ANR in android.process.media
07-07 15:28:31.420: E/ActivityManager(376): PID: 462
07-07 15:28:31.420: E/ActivityManager(376): Reason: Broadcast of Intent { act=android.intent.action.MEDIA_MOUNTED dat=file:///storage/sdcard flg=0x10 cmp=com.android.providers.downloads/.DownloadReceiver (has extras) }
07-07 15:28:31.420: E/ActivityManager(376): Load: 10.6 / 5.54 / 2.39
07-07 15:28:31.420: E/ActivityManager(376): CPU usage from 3147ms to -105954ms ago:
07-07 15:28:31.420: E/ActivityManager(376):   32% 52/surfaceflinger: 26% user + 6% kernel / faults: 579 minor
07-07 15:28:31.420: E/ActivityManager(376):   30% 62/adbd: 4.1% user + 26% kernel / faults: 34 minor
07-07 15:28:31.420: E/ActivityManager(376):   10% 376/system_server: 5.9% user + 4.6% kernel / faults: 2276 minor 1 major
07-07 15:28:31.420: E/ActivityManager(376):   6.4% 95/bootanimation: 5.3% user + 1% kernel
07-07 15:28:31.420: E/ActivityManager(376):   3.7% 536/com.android.launcher: 2.5% user + 1.2% kernel / faults: 2112 minor 2 major
07-07 15:28:31.420: E/ActivityManager(376):   2.1% 524/com.android.phone: 1.1% user + 0.9% kernel / faults: 1613 minor 3 major
07-07 15:28:31.420: E/ActivityManager(376):   1.9% 427/com.android.systemui: 1.3% user + 0.6% kernel / faults: 792 minor 12 major
07-07 15:28:31.420: E/ActivityManager(376):   1.8% 510/com.android.inputmethod.latin: 1% user + 0.8% kernel / faults: 1920 minor 4 major
07-07 15:28:31.420: E/ActivityManager(376):   1.7% 26/mtdblock1: 0% user + 1.7% kernel
07-07 15:28:31.420: E/ActivityManager(376):   1.1% 25/mtdblock0: 0% user + 1.1% kernel
07-07 15:28:31.420: E/ActivityManager(376):   0.3% 50/debuggerd: 0.1% user + 0.1% kernel / faults: 368 minor
07-07 15:28:31.420: E/ActivityManager(376):   0.2% 39/flush-31:1: 0% user + 0.2% kernel
07-07 15:28:31.420: E/ActivityManager(376):   0.3% 462/android.process.media: 0.1% user + 0.2% kernel / faults: 135 minor 1 major
07-07 15:28:31.420: E/ActivityManager(376):   0.1% 137/logcat: 0% user + 0.1% kernel
07-07 15:28:31.420: E/ActivityManager(376):   0.1% 41/jbd2/mtdblock1-: 0% user + 0.1% kernel
07-07 15:28:31.420: E/ActivityManager(376):   0.1% 43/kworker/0:2: 0% user + 0.1% kernel
07-07 15:28:31.420: E/ActivityManager(376):   0.1% 49/netd: 0% user + 0% kernel / faults: 14 minor
07-07 15:28:31.420: E/ActivityManager(376):   0% 46/servicemanager: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):   0% 53/zygote: 0% user + 0% kernel / faults: 51 minor
07-07 15:28:31.420: E/ActivityManager(376):   0% 3/ksoftirqd/0: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):   0% 55/mediaserver: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):   0% 1//init: 0% user + 0% kernel / faults: 1 minor
07-07 15:28:31.420: E/ActivityManager(376):   0% 51/rild: 0% user + 0% kernel / faults: 2 minor
07-07 15:28:31.420: E/ActivityManager(376):   0% 13/fsnotify_mark: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):  +0% 569/android.process.acore: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):  +0% 605/sh: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):  +0% 607/app_process: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376): 100% TOTAL: 54% user + 37% kernel + 8.4% softirq
07-07 15:28:31.420: E/ActivityManager(376): CPU usage from 26383ms to 99997ms later:
07-07 15:28:31.420: E/ActivityManager(376):   41% 62/adbd: 5.6% user + 35% kernel
07-07 15:28:31.420: E/ActivityManager(376):     15% 133/adbd: 3.8% user + 12% kernel
07-07 15:28:31.420: E/ActivityManager(376):     10% 132/adbd: 1% user + 9.7% kernel
07-07 15:28:31.420: E/ActivityManager(376):     9% 62/adbd: 1.1% user + 7.9% kernel
07-07 15:28:31.420: E/ActivityManager(376):     5.2% 589/adbd: 0.1% user + 5.1% kernel
07-07 15:28:31.420: E/ActivityManager(376):   30% 52/surfaceflinger: 22% user + 7.2% kernel / faults: 340 minor
07-07 15:28:31.420: E/ActivityManager(376):     26% 52/surfaceflinger: 21% user + 4.9% kernel
07-07 15:28:31.420: E/ActivityManager(376):     1.7% 82/DispSync: 0.6% user + 1% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0.6% 92/EventThread: 0.1% user + 0.5% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0.2% 139/Binder_3: 0% user + 0.2% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0.2% 364/Binder_5: 0.1% user + 0.1% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0.2% 81/Binder_1: 0% user + 0.2% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0.2% 363/Binder_4: 0% user + 0.1% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0.2% 83/Binder_2: 0% user + 0.2% kernel
07-07 15:28:31.420: E/ActivityManager(376):   7% 376/system_server: 3.3% user + 3.7% kernel / faults: 158 minor
07-07 15:28:31.420: E/ActivityManager(376):     4.3% 381/Signal Catcher: 1.1% user + 3.1% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0.7% 391/ActivityManager: 0.3% user + 0.4% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0.2% 410/NetworkStats: 0.1% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0.2% 389/SensorService: 0.1% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0.1% 383/Compiler: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0.1% 509/watchdog: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 477/Binder_3: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 554/Binder_5: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 555/Binder_6: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 409/NetdConnector: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 590/Binder_7: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 388/Binder_2: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 392/android.bg: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 387/Binder_1: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 395/android.ui: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 523/NetworkTimeUpda: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 553/Binder_4: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 376/system_server: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 394/android.fg: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 396/android.io: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 398/FileObserver: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 401/PowerManagerSer: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 418/NsdService: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 419/mDnsConnector: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 423/UEventObserver: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 424/backup: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 380/GC: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 390/WindowManager: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 404/InputDispatcher: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 406/MountService: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 407/VoldConnector: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 412/WifiP2pService: 0% user + 0% kernel
07-07 15:28:31.420: E/ActivityManager(376):     0% 413/WifiStateMachin: 0% user +
07-07 15:28:37.150: E/BluetoothAdapter(524): Bluetooth binder is null
07-07 15:28:37.470: E/memtrack(607): Couldn't load memtrack module (No such file or directory)
07-07 15:28:37.470: E/android.os.Debug(607): failed to load memtrack module: -2
07-07 15:29:21.140: E/ActivityManager(376): ANR in com.android.systemui
07-07 15:29:21.140: E/ActivityManager(376): PID: 427
07-07 15:29:21.140: E/ActivityManager(376): Reason: Executing service com.android.systemui/.ImageWallpaper
07-07 15:29:21.140: E/ActivityManager(376): Load: 10.54 / 6.34 / 2.83
07-07 15:29:21.140: E/ActivityManager(376): CPU usage from 111ms to 37067ms later:
07-07 15:29:21.140: E/ActivityManager(376):   49% 52/surfaceflinger: 45% user + 4.1% kernel / faults: 367 minor
07-07 15:29:21.140: E/ActivityManager(376):   18% 376/system_server: 11% user + 6.3% kernel / faults: 1370 minor
07-07 15:29:21.140: E/ActivityManager(376):   9.3% 95/bootanimation: 8.4% user + 0.8% kernel
07-07 15:29:21.140: E/ActivityManager(376):   6.8% 427/com.android.systemui: 5.2% user + 1.5% kernel / faults: 1035 minor
07-07 15:29:21.140: E/ActivityManager(376):   6.2% 536/com.android.launcher: 4% user + 2.2% kernel / faults: 2779 minor
07-07 15:29:21.140: E/ActivityManager(376):   4.4% 524/com.android.phone: 2.8% user + 1.6% kernel / faults: 936 minor
07-07 15:29:21.140: E/ActivityManager(376):   1.2% 25/mtdblock0: 0% user + 1.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0.8% 62/adbd: 0% user + 0.8% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0.5% 569/android.process.acore: 0.3% user + 0.1% kernel / faults: 196 minor 23 major
07-07 15:29:21.140: E/ActivityManager(376):   0.3% 137/logcat: 0% user + 0.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0.1% 51/rild: 0% user + 0% kernel / faults: 1 minor
07-07 15:29:21.140: E/ActivityManager(376):   0.1% 26/mtdblock1: 0% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0.1% 46/servicemanager: 0% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0% 53/zygote: 0% user + 0% kernel / faults: 51 minor
07-07 15:29:21.140: E/ActivityManager(376):   0% 41/jbd2/mtdblock1-: 0% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0% 43/kworker/0:2: 0% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0% 1//init: 0% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0% 3/ksoftirqd/0: 0% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0% 39/flush-31:1: 0% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):  +0% 626/com.android.defcontainer: 0% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):  +0% 640/kworker/0:1: 0% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376): 100% TOTAL: 80% user + 19% kernel + 0.1% softirq
07-07 15:29:21.140: E/ActivityManager(376): CPU usage from 26403ms to 33985ms later:
07-07 15:29:21.140: E/ActivityManager(376):   51% 52/surfaceflinger: 46% user + 5.1% kernel / faults: 68 minor
07-07 15:29:21.140: E/ActivityManager(376):     43% 52/surfaceflinger: 41% user + 2.5% kernel
07-07 15:29:21.140: E/ActivityManager(376):     4.7% 82/DispSync: 0.4% user + 4.3% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.8% 92/EventThread: 0.2% user + 0.5% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.4% 83/Binder_2: 0.1% user + 0.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.4% 364/Binder_5: 0.1% user + 0.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.2% 363/Binder_4: 0.1% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.1% 81/Binder_1: 0.1% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.1% 139/Binder_3: 0% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):   14% 376/system_server: 9.1% user + 4.9% kernel / faults: 143 minor
07-07 15:29:21.140: E/ActivityManager(376):     5.1% 391/ActivityManager: 2.1% user + 2.9% kernel
07-07 15:29:21.140: E/ActivityManager(376):     1.6% 383/Compiler: 1.3% user + 0.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):     1.3% 390/WindowManager: 1.1% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.5% 477/Binder_3: 0.4% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.5% 555/Binder_6: 0.2% user + 0.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.5% 590/Binder_7: 0.2% user + 0.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.5% 622/Binder_A: 0.2% user + 0.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.4% 387/Binder_1: 0.4% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.4% 553/Binder_4: 0.1% user + 0.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.4% 599/Binder_9: 0.2% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.2% 392/android.bg: 0.1% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.2% 395/android.ui: 0.2% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.2% 554/Binder_5: 0.1% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.1% 376/system_server: 0% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.1% 394/android.fg: 0.1% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.1% 401/PowerManagerSer: 0% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.1% 623/Binder_B: 0.1% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):   9.3% 95/bootanimation: 8.5% user + 0.8% kernel
07-07 15:29:21.140: E/ActivityManager(376):     9% 108/BootAnimation: 8.3% user + 0.7% kernel
07-07 15:29:21.140: E/ActivityManager(376):   8.4% 536/com.android.launcher: 5.3% user + 3.1% kernel / faults: 1248 minor
07-07 15:29:21.140: E/ActivityManager(376):     7.1% 536/ndroid.launcher: 4.6% user + 2.4% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.7% 543/Compiler: 0.3% user + 0.4% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.1% 540/GC: 0% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.1% 551/Binder_1: 0% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):   7.2% 427/com.android.systemui: 6.6% user + 0.6% kernel / faults: 133 minor
07-07 15:29:21.140: E/ActivityManager(376):     6.7% 427/ndroid.systemui: 6.1% user + 0.6% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.3% 434/Compiler: 0.3% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.1% 446/Binder_2: 0.1% user + 0% kernel
07-07 15:29:21.140: E/ActivityManager(376):   3.6% 524/com.android.phone: 2.1% user + 1.5% kernel / faults: 31 minor
07-07 15:29:21.140: E/ActivityManager(376):     2.1% 524/m.android.phone: 1% user + 1% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.9% 561/RILReceiver: 0.7% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.6% 532/Compiler: 0.4% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.1% 559/RILSender: 0% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):   1.7% 62/adbd: 0% user + 1.7% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.7% 62/adbd: 0% user + 0.7% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.5% 132/adbd: 0% user + 0.5% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.2% 133/adbd: 0% user + 0.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):   1.2% 25/mtdblock0: 0% user + 1.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0.5% 51/rild: 0.2% user + 0.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.4% 73/rild: 0.1% user + 0.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):     0.1% 71/rild: 0% user + 0.1% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0.5% 137/logcat: 0% user + 0.5% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0.2% 46/servicemanager: 0% user + 0.2% kernel
07-07 15:29:21.140: E/ActivityManager(376):   0.3% 569/android.process.acore: 0% user + 0.3% kernel / faults: 60 minor 1 major
07-07 15:29:21.140: E/ActivityManager(376):     0.1% 5
07-07 15:29:25.620: E/JavaBinder(376): !!! FAILED BINDER TRANSACTION !!!
07-07 15:29:25.730: E/JavaBinder(376): !!! FAILED BINDER TRANSACTION !!!
07-07 15:29:25.920: E/JavaBinder(376): !!! FAILED BINDER TRANSACTION !!!
07-07 15:29:26.030: E/JavaBinder(376): !!! FAILED BINDER TRANSACTION !!!
07-07 15:29:34.220: E/InputDispatcher(376): channel 'b20dc010 StatusBar (server)' ~ Channel is unrecoverably broken and will be disposed!
07-07 15:29:34.240: E/InputDispatcher(376): channel 'b2034350 SearchPanel (server)' ~ Channel is unrecoverably broken and will be disposed!
07-07 15:29:34.240: E/InputDispatcher(376): channel 'b2034840 NavigationBar (server)' ~ Channel is unrecoverably broken and will be disposed!
07-07 15:29:34.240: E/InputDispatcher(376): channel 'b2052500 SearchPanel (server)' ~ Channel is unrecoverably broken and will be disposed!
07-07 15:29:34.240: E/InputDispatcher(376): channel 'b2076f58 Keyguard (server)' ~ Channel is unrecoverably broken and will be disposed!
07-07 15:29:54.380: E/NetdConnector(376): NDC Command {8 bandwidth gettetherstats} took too long (865ms)
07-07 15:29:56.470: E/NetdConnector(376): NDC Command {9 bandwidth setglobalalert 2097152} took too long (781ms)
```
wären noch mehr Meldungen gewesen passte aber nicht mehr rein

kannst du was damit anfangen?


----------



## themrdomi (14. Jul 2014)

Er sagt dir doch, was er nicht hat:
Ein Ordner existiert nicht, und jede Menge anderer Fehlermeldungen, das liegt eher nicht an meinem Code, denke ich.
Hast du sonst noch was verändert?

Lg


----------



## DrDevil_Gamer (14. Jul 2014)

Nein ich habe sonst nix geändert. Wenn ich überall mp.stop(); mache
dann geht es nicht mach ich aber die ganzen mp.stop(); weg dann geht es.


----------



## dzim (15. Jul 2014)

Vielleicht vorher mal testen, ob denn was läuft? Vielleicht gibt es ja eine Methode dafür. (Ich hab damit noch nie was gemacht, aber es erschiene mir plausibel.)


----------



## DrDevil_Gamer (15. Jul 2014)

Also dieser Code Ausschnitt mit 

```
if(e==b1){
		 mp = MediaPlayer.create(getApplicationContext(), R.raw.doofzicke_ey);
		 mp.stop();
		mp.start();
```
geht nicht.

Ich habe eine Neue test App erstellt. Da habe dann nur zwei Buttons und Sounds hinzugefügt.
Anschließend habe ich den Code Ausschnitt wie oben verwendet und es es hat nicht geklappt.
Dann habe ich etwas anderes versucht, mit zwei MediaPlayer mp mp1 hat aber auch nicht funktioniert. Danach habe ich das getan

```
public void onClick(View e) {
		if(e==b1){
			mp =MediaPlayer.create(getApplicationContext(), R.raw.doofzicke_ey);
			mp.start();
			if(mp1!=null && mp1.isPlaying()){
				mp1.stop();
			}
			
		}else if(e==b2){
			mp1 = MediaPlayer.create(getApplicationContext(), R.raw.du_affe);
			mp1.start();
			if(mp!=null && mp.isPlaying()){
				mp.stop();
```
das hat dann funktioniert aber in meinem Soundboard habe ich 37 Buttons, dass heißt ja ich müsste 37 MediaPlayer haben (wenn ich nur ein MediaPlayer habe geht es nicht) und bei jedem Button 36 if abfragen machen oder nicht?


----------



## dzim (15. Jul 2014)

ich denke, es genügt, wenn du deinen MediaPlayer so hier holst:

```
public void onClick(View e) {
        // stop running MediaPlayers
        if(mp!=null && mp.isPlaying()) {
                mp.stop();
        }
        // dicide, which music needs to be played next
        if(e==b1) {
            mp =MediaPlayer.create(getApplicationContext(), R.raw.doofzicke_ey);
        } else if(e==b2){
            mp = MediaPlayer.create(getApplicationContext(), R.raw.du_affe);
        }
        // start the next sound
        mp.start();
}
```

Vielleicht solltest du auch noch mal hier
Media Playback | Android Developers
oder hier 
MediaPlayer | Android Developers
schauen.
Es scheint so, als wäre es auch sinnvoll, das Playback in den Background zu schieben (IntentService oder so)...


----------



## DrDevil_Gamer (15. Jul 2014)

Danke du hast mir mal wieder geholfen. Es funktioniert so wie ich es haben wollte.:toll::applaus:

Noch eine kleine frage, OnClickListener ist ja wenn ich einmal auf dem Button drücke und dann etwas passiert. Gibt es auch was wo ich de Button gedrückt halten muss bevor was passiert bzw wenn ich denn Button kurz drücke dann soll er denn Sound abspielen und wenn ich lang drücke dann soll er denn Sound stoppen.

Hoffe du kennst dich da ein bisschen aus und wenn nicht ist auch nicht so schlimm hab ja immerhin dank deiner Hilfe das was ich wollte geschafft.


----------



## dzim (16. Jul 2014)

Nie Probiert, aber vielleicht kann dir eine onTouchListener helfen:
Button
View#setOnTouchListener()

Für ich klingt das jedenfalls nach einer logischen Wahl.


----------



## chris199 (21. Jan 2015)

hi, wollte auch sowas ähnliches machen, aber bei mir will es einfach nicht stoppen ;(

```
package com.szulc.wg15d;

import android.support.v7.app.ActionBarActivity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity{
boolean mainisopen = true;
	
public MediaPlayer mp1;
public MediaPlayer mp2;
public MediaPlayer mp3;
public MediaPlayer mp4;
public MediaPlayer mp5;
public MediaPlayer mp6;
Button allemittwochwieder;
Button duda;
Button dudabaum;
Button dudada;
Button klingeuter;
Button ruhig;

@Override 
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		allemittwochwieder = (Button) findViewById (R.id.button3);
		allemittwochwieder.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp1 = MediaPlayer.create(getApplicationContext(),  R.raw.allemittwochwieder);
			mp1.start();
		}
		});
		
		duda = (Button) findViewById (R.id.button5);
		duda.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.duda);
		mp.start();
		}
		});
		
		dudada = (Button) findViewById (R.id.button6);
		dudada.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.dudada);
		mp.start();
		}
		});
		
		klingeuter = (Button) findViewById (R.id.button4);
		klingeuter.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.klingeuter);
		mp.start();
		}
		});
		
		ruhig = (Button) findViewById (R.id.button1);
		ruhig.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				if(mp1!=null && mp1.isPlaying()){
					mp1.stop();
				}
				MediaPlayer mp2 = MediaPlayer.create(getApplicationContext(),  R.raw.ruhig);
				mp2.start();
				
				
			}});
		
}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.toString().equals("Schließen")){
			showDialog(10);
		}
		return true;
	}
	@Override 
	protected Dialog onCreateDialog (int id) { 
		switch (id) {
		case 10: 
			Builder builder = new AlertDialog.Builder(this); 
			builder.setMessage("Applikation wird geschlossen!"); 
			builder.setCancelable(true); 
			builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) { 
					MainActivity.this.finish(); } }); 
			builder.setNegativeButton("Nein, doch nicht!", new DialogInterface.OnClickListener() { 
				@Override
				public void onClick(DialogInterface dialog, int which) { 
					Toast.makeText(getApplicationContext(), "Applikation wird fortgesetzt", Toast.LENGTH_LONG).show(); } });
			AlertDialog dialog = builder.create();
			dialog.show();
			} return super.onCreateDialog(id); }
	public void weitere (View view) {
		setContentView(R.layout.weitere);
		mainisopen = false;
		
		dudabaum = (Button) findViewById (R.id.button1);
		dudabaum.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.dudabaum);
		mp.start();
		}
		});
		
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event){
		if (keyCode == KeyEvent.KEYCODE_BACK && mainisopen ==false){
			mainisopen = true;
			setContentView(R.layout.activity_main);
			return true;
		}
		return super.onKeyDown(keyCode,  event);
		}
	
		
	}
```
wo ist der fehler?
hab es erstmal mit mp1 und mp2 versucht. hab da vieles ausgetestet. also nicht verwirt sein 
hab es erstmal mit ruhig und allemittwochwieder ausgetestet.


----------



## dzim (24. Jan 2015)

Nur so als Frage: Warum deklarierst du MediaPlayer mp1-6 wenn du in den onClickListenern immer dann doch nur einen neuen aufmachst, der dann auch nur im Kontext des Listeners gültig ist.


----------



## chris199 (26. Jan 2015)

das war nur ein versuch, den vorherigen zu stoppen.


----------



## dzim (27. Jan 2015)

Und das ist das Problem, denke ich... Es wir ja jedes Mal ein neues Playback-Objekt angelegt und somit wird es schwer, einen bereits laufenden wieder zu stoppen...


----------



## chris199 (27. Jan 2015)

```
package com.szulc.wg15d;

import android.support.v7.app.ActionBarActivity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity{
boolean mainisopen = true;
	
public MediaPlayer mp;
Button allemittwochwieder;
Button duda;
Button dudabaum;
Button dudada;
Button klingeuter;
Button ruhig;
Button hanni;
Button ich_hab_dich_lieb;
Button ich_bin_nicht_schuld;
Button Witzig;
Button Tschhh;
Button Robin;
Button Applaus;
Button Jessica_Duda;

@Override 
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		allemittwochwieder = (Button) findViewById (R.id.button3);
		allemittwochwieder.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.allemittwochwieder);
			mp.start();
		}
		});
		
		duda = (Button) findViewById (R.id.button5);
		duda.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.duda);
		mp.start();
		}
		});
		
		dudada = (Button) findViewById (R.id.button6);
		dudada.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.dudada);
		mp.start();
		}
		});
		
		klingeuter = (Button) findViewById (R.id.button4);
		klingeuter.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.klingeuter);
		mp.start();
		}
		});
		
		ruhig = (Button) findViewById (R.id.button1);
		ruhig.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				if(mp!=null && mp.isPlaying()){
					mp.stop();
				}
				MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.ruhig);
				mp.start();
				
				
			}});
		
}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.toString().equals("Schließen")){
			showDialog(10);
		}
		return true;
	}
	@Override 
	protected Dialog onCreateDialog (int id) { 
		switch (id) {
		case 10: 
			Builder builder = new AlertDialog.Builder(this); 
			builder.setMessage("Applikation wird geschlossen!"); 
			builder.setCancelable(true); 
			builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) { 
					MainActivity.this.finish(); } }); 
			builder.setNegativeButton("Nein, doch nicht!", new DialogInterface.OnClickListener() { 
				@Override
				public void onClick(DialogInterface dialog, int which) { 
					Toast.makeText(getApplicationContext(), "Applikation wird fortgesetzt", Toast.LENGTH_LONG).show(); } });
			AlertDialog dialog = builder.create();
			dialog.show();
			} return super.onCreateDialog(id); }
	public void weitere (View view) {
		setContentView(R.layout.weitere);
		mainisopen = false;
		
		dudabaum = (Button) findViewById (R.id.button1);
		dudabaum.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.dudabaum);
		mp.start();
		}
		});
		Witzig = (Button) findViewById (R.id.button2);
		Witzig.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.witzig);
			mp.start();
		}
		});
		Tschhh = (Button) findViewById (R.id.button3);
		Tschhh.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.tschhh);
			mp.start();
		}
		});
		Robin = (Button) findViewById (R.id.button4);
		Robin.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.robin);
			mp.start();
		}
		});
		Applaus = (Button) findViewById (R.id.button5);
		Applaus.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.klaptschen);
			mp.start();
		}
		});
		Jessica_Duda = (Button) findViewById (R.id.button6);
		Jessica_Duda.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v){
			MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.jessicaduda);
			mp.start();
		}
		});
		}
	
	
		public void noch_mehr (View view) {
			setContentView(R.layout.noch_mehr);
			mainisopen = false;
			
			hanni = (Button) findViewById (R.id.button3);
			hanni.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.hanni);
			mp.start();
			}
			});
			ich_bin_nicht_schuld = (Button) findViewById (R.id.button2);
			ich_bin_nicht_schuld.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.ichbinnichtschuld);
			mp.start();
			}
			});
			ich_hab_dich_lieb = (Button) findViewById (R.id.button1);
			ich_hab_dich_lieb.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				MediaPlayer mp = MediaPlayer.create(getApplicationContext(),  R.raw.ichhabdichlieb);
			mp.start();
			}
			});
		}
		
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event){
		if (keyCode == KeyEvent.KEYCODE_BACK && mainisopen ==false){
			mainisopen = true;
			setContentView(R.layout.activity_main);
			return true;
		}
		return super.onKeyDown(keyCode,  event);
		}
	
		
	}
```
da hab ich alles wieder ordentlich gemacht.
bei ruhig habe ich mit if probiert, aber hat leider nicht so geklappt. wurde zwar genauso bei einem im internet gemacht, will aber nicht bei mir. bin noch nicht sehr erfahren mit java, deswegen die frage, was da falsch ist.


----------

