here is activity_main.xml
xmlns:app="****"
xmlns:tools="****"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.thepiratebay.keven.MainActivity"
android:background="@drawable/background">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="51dp"
android:layout_y="47dp"
android:onClick="sound1"
android:text="bonnefete1" />
and here is mainactivity.java:
package org.thepiratebay.keven;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
MediaPlayer sound1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sound1 = MediaPlayer.create(this, R.raw.a1toutunmot);
}
public void sound1(View view) {
sound1.start();
}
}
i found someone saying
MediaPlayer mp = MediaPlayer.create(YourActivity.this, R.raw.mysound);
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
}
});
mp.start();
This is the best way I found to play a sound in Android. Hope it helps!
not sure where to fit this code...
anyways any clue will be greatly appreciated
thanks
nate