首页 > 解决方案 > 为什么我的 .mp3 没有播放,而是显示“prepare(); is an unreported exception IOException; must be catch or declare to be throw”?

问题描述

我创建了 mp.start(); 如你看到的。没有用(声音不会播放,虽然我手机上的媒体音量为 100%)所以我添加了 prepare(); 在前面,正如有人说尝试那样。现在我遇到了 IOException 问题...

package com.example.test.test;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class AudioPlayer extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_audio_player);

    AudioManager audioManager = (AudioManager)
    getSystemService(Context.AUDIO_SERVICE);
    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);

    MediaPlayer mp = MediaPlayer.create(AudioPlayer.this, R.raw.xy_sound);
    mp.prepare();
    mp.start();

    try {
        prepare();
    }
    catch(IOException e) {
        e.printStackTrace();
    }
}
}

这是日志

06-12 22:15:20.003 32090-32090/? I/art: Late-enabling -Xcheck:jni
06-12 22:15:20.029 32090-32097/? I/art: Debugger is no longer active
Starting a blocking GC Instrumentation
06-12 22:15:20.050 32090-32090/? W/System: ClassLoader referenced unknown     path: /data/app/com.example.daniel.project123-1/lib/arm
06-12 22:15:20.164 32090-32090/? W/art: Before Android 4.1, method     android.graphics.PorterDuffColorFilter     android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.g    raphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
06-12 22:15:20.759 32090-32159/? I/Adreno: QUALCOMM build                   : 48a5bf5, I15255e4b4a
Build Date                       : 02/22/17
OpenGL ES Shader Compiler Version: XE031.09.00.03
Local Branch                     : 
Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.5.5.R1.07.00.00.269.019
Remote Branch                    : NONE
Reconstruct Branch               : NOTHING
06-12 22:15:20.765 32090-32159/? I/OpenGLRenderer: Initialized EGL, version 1.4
06-12 22:15:20.765 32090-32159/? D/OpenGLRenderer: Swap behavior 1
06-12 22:15:32.240 32090-32090/com.example.daniel.project123
W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection

标签: androidandroid-studio

解决方案


推荐阅读