Autore Topic: Media player creato da Uri non funziona  (Letto 486 volte)

Offline theKuston

  • Nuovo arrivato
  • *
  • Post: 48
  • Respect: 0
    • Google+
    • Mostra profilo
  • Dispositivo Android:
    Google Nexus 5
  • Play Store ID:
    K-soft
  • Sistema operativo:
    windows 8.1, Ubuntu 14
Media player creato da Uri non funziona
« il: 14 Marzo 2015, 17:23:29 CET »
0
Weeee
Allora sto cercando di fare un media player a partire da un uri ma non funzona...
Il mio codice Java:
Codice (Java): [Seleziona]
Uri uriSound;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button play = (Button) findViewById(R.id.button2);
        Button select = (Button) findViewById(R.id.button);
        select.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(i, 1);
            }
        });
        play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MediaPlayer mediaPlayer = MediaPlayer.create(MainActivity.this,uriSound);
                mediaPlayer.start();
            }
        });
    }
    protected void onActivityResult(int requestCode,int resultCode,Intent data){
        if(requestCode == 1){
            if(resultCode == RESULT_OK){
                uriSound=data.getData();
            }
            Log.d("uri",""+uriSound);
            Log.d("ringtone",Settings.System.DEFAULT_RINGTONE_URI+"");
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
e il mio logcat:
Codice: [Seleziona]
03-14 17:22:16.305  29987-29987/k.soft.audiodemo I/art﹕ Late-enabling -Xcheck:jni
03-14 17:22:16.327  29987-29997/k.soft.audiodemo I/art﹕ Debugger is no longer active
03-14 17:22:16.348  29987-29987/k.soft.audiodemo W/ActivityThread﹕ Application k.soft.audiodemo is waiting for the debugger on port 8100...
03-14 17:22:16.351  29987-29987/k.soft.audiodemo I/System.out﹕ Sending WAIT chunk
03-14 17:22:17.352  29987-29997/k.soft.audiodemo I/art﹕ Debugger is active
03-14 17:22:17.356  29987-29987/k.soft.audiodemo I/System.out﹕ Debugger has connected
03-14 17:22:17.356  29987-29987/k.soft.audiodemo I/System.out﹕ waiting for debugger to settle...
03-14 17:22:17.557  29987-29987/k.soft.audiodemo I/System.out﹕ waiting for debugger to settle...
03-14 17:22:17.757  29987-29987/k.soft.audiodemo I/System.out﹕ waiting for debugger to settle...
03-14 17:22:17.957  29987-29987/k.soft.audiodemo I/System.out﹕ waiting for debugger to settle...
03-14 17:22:18.158  29987-29987/k.soft.audiodemo I/System.out﹕ waiting for debugger to settle...
03-14 17:22:18.358  29987-29987/k.soft.audiodemo I/System.out﹕ waiting for debugger to settle...
03-14 17:22:18.559  29987-29987/k.soft.audiodemo I/System.out﹕ waiting for debugger to settle...
03-14 17:22:18.759  29987-29987/k.soft.audiodemo I/System.out﹕ waiting for debugger to settle...
03-14 17:22:18.960  29987-29987/k.soft.audiodemo I/System.out﹕ debugger has settled (1310)
03-14 17:22:19.036  29987-30041/k.soft.audiodemo D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
03-14 17:22:19.041  29987-29987/k.soft.audiodemo D/Atlas﹕ Validating map...
03-14 17:22:19.101  29987-30041/k.soft.audiodemo I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 01/14/15, ab0075f, Id3510ff6dc
03-14 17:22:19.101  29987-30041/k.soft.audiodemo I/OpenGLRenderer﹕ Initialized EGL, version 1.4
03-14 17:22:19.135  29987-30041/k.soft.audiodemo D/OpenGLRenderer﹕ Enabling debug mode 0
03-14 17:22:30.391  29987-30041/k.soft.audiodemo D/OpenGLRenderer﹕ endAllStagingAnimators on 0xb4991980 (RippleDrawable) with handle 0xaef00050
03-14 17:22:33.093  29987-29987/k.soft.audiodemo D/uri﹕ content://media/external/audio/media/57
03-14 17:22:33.093  29987-29987/k.soft.audiodemo D/ringtone﹕ content://settings/system/ringtone
03-14 17:22:34.421  29987-29987/k.soft.audiodemo D/MediaPlayer﹕ Couldn't open file on client side, trying server side
03-14 17:22:34.426  29987-29987/k.soft.audiodemo E/MediaPlayer﹕ Unable to create media player
03-14 17:22:34.427  29987-29987/k.soft.audiodemo D/MediaPlayer﹕ create failed:
    java.io.IOException: setDataSource failed.: status=0x80000000
            at android.media.MediaPlayer.nativeSetDataSource(Native Method)
            at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1071)
            at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1060)
            at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1014)
            at android.media.MediaPlayer.setDataSource(MediaPlayer.java:957)
            at android.media.MediaPlayer.create(MediaPlayer.java:864)
            at android.media.MediaPlayer.create(MediaPlayer.java:841)
            at android.media.MediaPlayer.create(MediaPlayer.java:820)
            at k.soft.audiodemo.MainActivity$2.onClick(MainActivity.java:36)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            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:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
03-14 17:22:34.428  29987-29987/k.soft.audiodemo D/AndroidRuntime﹕ Shutting down VM
03-14 17:22:34.428  29987-29987/k.soft.audiodemo E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: k.soft.audiodemo, PID: 29987
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.start()' on a null object reference
            at k.soft.audiodemo.MainActivity$2.onClick(MainActivity.java:37)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            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:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
03-14 17:22:36.181  29987-29987/k.soft.audiodemo I/Process﹕ Sending signal. PID: 29987 SIG: 9

Grazie 1000000 a tutti!
Tutte le mie applicazioni sul play store:
https://play.google.com/store/apps/developer?id=K-soft

Offline theKuston

  • Nuovo arrivato
  • *
  • Post: 48
  • Respect: 0
    • Google+
    • Mostra profilo
  • Dispositivo Android:
    Google Nexus 5
  • Play Store ID:
    K-soft
  • Sistema operativo:
    windows 8.1, Ubuntu 14
Re:Media player creato da Uri non funziona
« Risposta #1 il: 31 Marzo 2015, 17:22:32 CEST »
0
Risolto, il problema era che non usavo la permission read_external_storage
Tutte le mie applicazioni sul play store:
https://play.google.com/store/apps/developer?id=K-soft