Commit 98f199dd authored by Martin LOISEAU's avatar Martin LOISEAU 🎄
Browse files

Add mp3 sound playing

parent 44b2206e
package com.example.qrquest;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.os.Environment;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -53,8 +58,10 @@ public class MainActivity extends AppCompatActivity {
mp3_reader.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Should play sound from an mp3 file", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
PlayTestMP3();
}
});
}
......@@ -80,4 +87,11 @@ public class MainActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item);
}
public boolean PlayTestMP3() {
mp = MediaPlayer.create(this, R.raw.robot_sound);
mp.setLooping(false);
mp.start();
return true;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment