android - 为什么我的 .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
解决方案
推荐阅读
- java - 在 android studio 的 xml 文件中命名字符串数组给我一个错误
- html - 我想获得带有所选值的下拉列表(更新到角度 10 及以上)
- javascript - 使用 JQuery clone() 时,为什么 remove() 不起作用
- android - 导航抽屉项目突出显示颜色超出角落的半径
- python - 如何在熊猫中制作一列分类组
- node.js - 猫鼬:在数组内应用对象值的 $addToSet?
- ios - Swift • 如何在 SwiftUI 中实现 Peek 和 Pop 功能?
- java - 我需要读取并加载一个文本文件并将元素添加到哈希表中;而是用户输入数据
- python - 如何使用从 github 下载的数据库文件夹在本地创建 MYSQL 数据库
- verilog - 4 位加减器 Verilog 代码错误