I'm trying to make a media player on my android phone, but I have some issues with Uri.parse()
.
I don't understand why my application is always crashing when I use Uri with Media Player.
But it works fine if I use a R.raw.file
method.
eg :
This works great
//...
mp = MediaPlayer.create(getApplicationContext(), R.raw.song);
mp.start();
//...
This makes the app crash
//...
u = Uri.parse("file://android_asset/song.ogg");
//What I use is a bit more complicated (see next commentary line), but it doesn't work with the previous line either
//u = Uri.parse(mySongs.get(position).toString());
mp = MediaPlayer.create(getApplicationContext(), u);
mp.start();
//...
Do you understand why the application is crashing everytime I'm using this, and could you explain to me please.
Here is my Logcat:
06-23 00:31:20.522 30428-30428/com.arnaudsolente.claptrapcitations I/art﹕ Late-enabling -Xcheck:jni
06-23 00:31:20.566 30428-30428/com.arnaudsolente.claptrapcitations W/ResourceType﹕ Found multiple library tables, ignoring...
06-23 00:31:21.904 30428-30428/com.arnaudsolente.claptrapcitations E/MediaPlayer-JNI﹕ QCMediaPlayer mediaplayer NOT present
06-23 00:31:21.922 30428-30428/com.arnaudsolente.claptrapcitations E/MediaPlayer﹕ Should have subtitle controller already set
06-23 00:31:21.963 30428-30531/com.arnaudsolente.claptrapcitations D/OpenGLRenderer﹕ Render dirty regions requested: true
06-23 00:31:21.969 30428-30428/com.arnaudsolente.claptrapcitations D/Atlas﹕ Validating map...
06-23 00:31:21.974 30428-30428/com.arnaudsolente.claptrapcitations E/MediaPlayer﹕ Should have subtitle controller already set
06-23 00:31:22.041 30428-30531/com.arnaudsolente.claptrapcitations I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
OpenGL ES Shader Compiler Version: E031.25.03.00
Build Date: 03/11/15 Wed
Local Branch: au016
Remote Branch:
Local Patches:
Reconstruct Branch:
06-23 00:31:22.042 30428-30531/com.arnaudsolente.claptrapcitations I/OpenGLRenderer﹕ Initialized EGL, version 1.4
06-23 00:31:22.056 30428-30531/com.arnaudsolente.claptrapcitations D/OpenGLRenderer﹕ Enabling debug mode 0
06-23 00:31:22.195 30428-30428/com.arnaudsolente.claptrapcitations I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@1f54ae44 time:40535044
06-23 00:31:47.625 30428-30428/com.arnaudsolente.claptrapcitations E/MediaPlayer﹕ start called in state 64
06-23 00:31:47.625 30428-30428/com.arnaudsolente.claptrapcitations E/MediaPlayer﹕ error (-38, 0)
06-23 00:31:47.626 30428-30428/com.arnaudsolente.claptrapcitations E/MediaPlayer﹕ Error (-38,0)
06-23 00:31:49.954 30428-30428/com.arnaudsolente.claptrapcitations I/Timeline﹕ Timeline: Activity_launch_request id:com.arnaudsolente.claptrapcitations time:40562803
06-23 00:31:50.066 30428-30428/com.arnaudsolente.claptrapcitations D/AndroidRuntime﹕ Shutting down VM
06-23 00:31:50.067 30428-30428/com.arnaudsolente.claptrapcitations E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.arnaudsolente.claptrapcitations, PID: 30428
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.arnaudsolente.claptrapcitations/com.arnaudsolente.claptrapcitations.Player}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.ArrayList.get(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.ArrayList.get(int)' on a null object reference
at com.arnaudsolente.claptrapcitations.Player.onCreate(Player.java:57)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)