播放mp3文件形式android原始文件夹获取错误Uri是<url suppress =“”>

时间:2015-06-27 22:59:35

标签: android android-mediaplayer

我需要在我的Android应用程序中从原始文件夹播放声音,我正在尝试做什么 -

    Uri alert = Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.ring_tone);
    mMediaPlayer = new MediaPlayer();
    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    try {
        mMediaPlayer.setDataSource(this, alert);
        mMediaPlayer.setVolume(Float.parseFloat(Double.toString(am.getStreamVolume(AudioManager.STREAM_NOTIFICATION) / 7.0)),
                Float.parseFloat(Double.toString(am.getStreamVolume(AudioManager.STREAM_NOTIFICATION) / 7.0)));

        mMediaPlayer.setLooping(true);
        mMediaPlayer.prepare();
        mMediaPlayer.start();

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mMediaPlayer.stop();
                mMediaPlayer.release();
            }
        }, 1000 * 60);

但我收到例外E/MediaPlayer﹕ Uri is <URL suppressed> D/MediaPlayer﹕ start() mUri is <URL suppressed>

我根据请求添加了LogCat -

06-27 11:00:00.118 26004-26004/com.altaoferta.reunio D/ActivityThread﹕ setTargetHeapUtilization:0.25 06-27 11:00:00.118 26004-26004/com.altaoferta.reunio D/ActivityThread﹕ setTargetHeapIdealFree:8388608 06-27 11:00:00.118 26004-26004/com.altaoferta.reunio D/ActivityThread﹕ setTargetHeapConcurrentStart:2097152 06-27 11:00:00.358 26004-26004/com.altaoferta.reunio D/dalvikvm﹕ GC_FOR_ALLOC freed 97K, 37% free 12543K/19779K, paused 26ms, total 26ms 06-27 11:00:00.378 26004-26004/com.altaoferta.reunio I/dalvikvm-heap﹕ Grow heap (frag case) to 27.252MB for 6551056-byte allocation 06-27 11:00:00.408 26004-26008/com.altaoferta.reunio D/dalvikvm﹕ GC_CONCURRENT freed 1K, 28% free 18939K/26183K, paused 7ms+4ms, total 28ms 06-27 11:00:00.438 26004-26004/com.altaoferta.reunio E/MediaPlayer﹕ Uri is <URL suppressed> 06-27 11:00:00.478 26004-26004/com.altaoferta.reunio D/MediaPlayer﹕ start() mUri is <URL suppressed> 06-27 11:00:00.568 26004-26004/com.altaoferta.reunio D/libEGL﹕ loaded /system/lib/egl/libEGL_adreno200.so 06-27 11:00:00.588 26004-26004/com.altaoferta.reunio D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_adreno200.so 06-27 11:00:00.588 26004-26004/com.altaoferta.reunio D/libEGL﹕ loaded /system/lib/egl/libGLESv2_adreno200.so

1 个答案:

答案 0 :(得分:0)

将URI声明更改为

Uri alert = Uri.parse("android.resource://" + this.getPackageName() + "/raw/ring_tone");

或使用

URI.getScheme() or URI.getPath().