使用MediaPlayer(这,Uri.parse())会使应用程序崩溃

时间:2015-06-21 01:21:35

标签: android parsing uri android-mediaplayer

我试图在我的Android手机上制作媒体播放器,但我在Uri.parse()时遇到了一些问题。 我不明白为什么当我使用Uri和Media Player时,我的应用程序总是崩溃。

但如果我使用R.raw.file方法,它可以正常工作。

例如:

这很棒

//...
    mp = MediaPlayer.create(getApplicationContext(), R.raw.song);
    mp.start();
//...

这会导致应用崩溃

//...
    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();
//...

您是否理解为什么我每次使用此应用程序时都会崩溃,请您解释一下。

这是我的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)

0 个答案:

没有答案