kein sounds

N

nixor

Neues Mitglied
0
Hi,

Bin neu hier und auch noch nicht sehr erfahren mit Android. Habe mir ein Beispiel angeschaut bei dem nach einem Tastendruck eine .mp3 datei abgespielt wird. Ich hab es gleich ausprobiert und keine Fehlermeldungen bekommen und auch die App hat sich geöffnet nur sobald ich auf den button klicke kommt die Fehlermeldung:

the application sound (process com.muo.sound) has stopped unexpectedly.

sound.java:
Code:
package com.muo.sound;

import com.muo.sound.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.media.MediaPlayer;


public class sound extends Activity {

    private Button playbutton;
    private MediaPlayer mp;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        playbutton = (Button)findViewById(R.id.playbutton);
        playbutton.setOnClickListener(new Button.OnClickListener() { 
            public void onClick (View v){ 
                mp = MediaPlayer.create(getBaseContext(), R.raw.testsound);
                mp.start();
            }
        });
    }
}
main.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<Button
    android:id="@+id/playbutton"
    android:layout_width="87px"
    android:layout_height="wrap_content"
    android:text="Play"
    android:layout_x="40px"
    android:layout_y="182px"
    >
</Button>
    
</LinearLayout>
Die mp3 Datei testsound.mp3 liegt im Ordner /res/raw


Hoffe ihr könnt mir helfen
 

Ähnliche Themen

S
Antworten
3
Aufrufe
637
swa00
swa00
A
Antworten
17
Aufrufe
1.852
starbright
S
5
Antworten
22
Aufrufe
1.421
590239
5
Zurück
Oben Unten