i'm just beginning to play around with the Android audio and i tried to use a simple media player to play a sound when the app is opened. It doesn't seem to play anything. Considering this is the example from the documentation (which doesn't work), i'm at a loss with how i should investigate deeper. I get no errors to guide me either. This is the code:
package com.example.audiotutorial;
import androidx.appcompat.app.AppCompatActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
MediaPlayer mediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mediaPlayer = MediaPlayer.create(this,R.raw.samplesound);
mediaPlayer.setVolume(50,50);
mediaPlayer.start();
}
}
I have a raw folder in my res. I tried using mp3, ogg and wav files. None of them worked. appreciate any ideas you might have.
Thanks,
LE: Regarding logcat i get a huge i/zygote warning that i can't paste because it's too long. This seems to be the conclusion:
2021-02-28 14:27:51.071 8489-8489/com.example.audiotutorial I/zygote: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
2021-02-28 14:27:51.071 8489-8489/com.example.audiotutorial I/zygote: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.example.audiotutorial-eXgKSoGwVETE-MaFh6QPPQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.audiotutorial-eXgKSoGwVETE-MaFh6QPPQ==/lib/x86, /system/lib, /vendor/lib]]
Afterwards that huge thing i have:
2021-02-28 14:27:51.355 8489-8521/com.example.audiotutorial D/OpenGLRenderer: HWUI GL Pipeline
2021-02-28 14:27:51.718 8489-8521/com.example.audiotutorial I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2021-02-28 14:27:51.718 8489-8521/com.example.audiotutorial I/OpenGLRenderer: Initialized EGL, version 1.4
2021-02-28 14:27:51.719 8489-8521/com.example.audiotutorial D/OpenGLRenderer: Swap behavior 1
2021-02-28 14:27:51.721 8489-8521/com.example.audiotutorial W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2021-02-28 14:27:51.721 8489-8521/com.example.audiotutorial D/OpenGLRenderer: Swap behavior 0
2021-02-28 14:27:51.737 8489-8521/com.example.audiotutorial D/EGL_emulation: eglCreateContext: 0x9d786ae0: maj 2 min 0 rcv 2
2021-02-28 14:27:51.748 8489-8521/com.example.audiotutorial D/EGL_emulation: eglMakeCurrent: 0x9d786ae0: ver 2 0 (tinfo 0x9d789ac0)
2021-02-28 14:27:51.861 8489-8521/com.example.audiotutorial D/EGL_emulation: eglMakeCurrent: 0x9d786ae0: ver 2 0 (tinfo 0x9d789ac0)
2021-02-28 14:27:53.373 8489-8489/com.example.audiotutorial E/libc: Access denied finding property "ro.serialno"
2021-02-28 14:27:53.354 8489-8489/com.example.audiotutorial W/e.audiotutorial: type=1400 audit(0.0:9): avc: denied { read } for name="u:object_r:serialno_prop:s0" dev="tmpfs" ino=5496 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:serialno_prop:s0 tclass=file permissive=0
2021-02-28 14:27:53.875 8489-8562/com.example.audiotutorial V/StudioTransport: Agent command stream started.
2021-02-28 14:27:53.877 8489-8561/com.example.audiotutorial V/StudioTransport: Transport agent connected to daemon.
2021-02-28 14:27:54.087 8489-8566/com.example.audiotutorial V/StudioTransport: Handling agent command 1200 for pid: 8489.
2021-02-28 14:27:54.087 8489-8566/com.example.audiotutorial V/StudioTransport: JNIEnv not attached
2021-02-28 14:27:54.084 8489-8489/com.example.audiotutorial W/Thread-2: type=1400 audit(0.0:10): avc: denied { write } for name="perfd" dev="dm-0" ino=65543 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:shell_data_file:s0 tclass=dir permissive=0
2021-02-28 14:27:54.389 8489-8566/com.example.audiotutorial V/StudioTransport: Handling agent command 1200 for pid: 8489.
2021-02-28 14:27:54.438 8489-8566/com.example.audiotutorial V/StudioTransport: Handling agent command 1200 for pid: 8489.
2021-02-28 14:27:55.294 8489-8566/com.example.audiotutorial W/zygote: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
2021-02-28 14:27:55.371 8489-8566/com.example.audiotutorial I/chatty: uid=10080(com.example.audiotutorial) Thread-2 identical 1 line
2021-02-28 14:27:55.494 8489-8566/com.example.audiotutorial W/zygote: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
2021-02-28 14:27:55.652 8489-8566/com.example.audiotutorial W/zygote: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
I found the issue. I was running the snap version of android studio under my Ubuntu 20.04 and apparently that has some limitations on which systems it can interact with; in this case, it doesn't get to use the system audio. If anyone else has a similar problem here are the steps i used to get to my conclusion: