java音频文件不能在安卓中播放
我有一个安卓应用程序,有两个按钮“播放”按钮和一个“暂停”按钮。如果按下播放按钮,则应启动mp3文件。暂停按钮将暂停音乐。这是我的代码:
public class MainActivity extends AppCompatActivity {
private MediaPlayer mp ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button playBtn = (Button) findViewById(R.id.play_id);
mp = MediaPlayer.create(this , R.raw.aroom);
playBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mp.start();
}
});
final Button pauseBtn = (Button) findViewById(R.id.pause_id);
playBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mp.pause();
}
});
}
}
这是我的日志:
07-10 18:31:11.010 15628-15628/? I/art: Late-enabling -Xcheck:jni
07-10 18:31:11.154 15628-15643/com.example.amir.myapplication E/HAL: load: id=gralloc != hmi->id=gralloc
07-10 18:31:11.224 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.amir.myapplication-2@split_lib_dependencies_apk.apk@classes.dex) because non-0 exit status
07-10 18:31:11.485 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.amir.myapplication-2@split_lib_slice_0_apk.apk@classes.dex) because non-0 exit status
07-10 18:31:11.543 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.amir.myapplication-2@split_lib_slice_1_apk.apk@classes.dex) because non-0 exit status
07-10 18:31:11.596 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.amir.myapplication-2@split_lib_slice_2_apk.apk@classes.dex) because non-0 exit status
07-10 18:31:11.648 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.amir.myapplication-2@split_lib_slice_3_apk.apk@classes.dex) because non-0 exit status
07-10 18:31:11.701 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.amir.myapplication-2@split_lib_slice_4_apk.apk@classes.dex) because non-0 exit status
07-10 18:31:11.757 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.amir.myapplication-2@split_lib_slice_5_apk.apk@classes.dex) because non-0 exit status
07-10 18:31:11.810 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.amir.myapplication-2@split_lib_slice_6_apk.apk@classes.dex) because non-0 exit status
07-10 18:31:11.875 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.amir.myapplication-2@split_lib_slice_7_apk.apk@classes.dex) because non-0 exit status
07-10 18:31:11.948 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.amir.myapplication-2@split_lib_slice_8_apk.apk@classes.dex) because non-0 exit status
07-10 18:31:12.009 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm/data@app@com.example.amir.myapplication-2@split_lib_slice_9_apk.apk@classes.dex) because non-0 exit status
07-10 18:31:12.015 15628-15628/com.example.amir.myapplication W/System: ClassLoader referenced unknown path: /data/app/com.example.amir.myapplication-2/lib/arm
07-10 18:31:12.033 15628-15628/com.example.amir.myapplication I/InstantRun: starting instant run server: is main process
07-10 18:31:12.173 15628-15628/com.example.amir.myapplication I/HwCust: Constructor found for class 安卓.app.HwCustHwWallpaperManagerImpl
07-10 18:31:12.204 15628-15628/com.example.amir.myapplication W/art: Before Android 4.1, method 安卓.graphics.PorterDuffColorFilter 安卓.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(安卓.graphics.PorterDuffColorFilter, 安卓.content.res.ColorStateList, 安卓.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in 安卓.graphics.drawable.Drawable
07-10 18:31:12.336 15628-15628/com.example.amir.myapplication I/HwCust: Constructor found for class 安卓.widget.HwCustTextViewImpl
07-10 18:31:12.345 15628-15628/com.example.amir.myapplication I/HwCust: Constructor found for class 安卓.widget.HwCustTextViewImpl
07-10 18:31:12.359 15628-15628/com.example.amir.myapplication I/MediaPlayer: setDataSource(40, 69464, 9958560)
07-10 18:31:12.405 15628-15628/com.example.amir.myapplication I/HwSecImmHelper: mSecurityInputMethodService is null
07-10 18:31:12.526 15628-15709/com.example.amir.myapplication E/HAL: load: id=gralloc != hmi->id=gralloc
07-10 18:31:12.527 15628-15709/com.example.amir.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
07-10 18:31:12.653 15628-15628/com.example.amir.myapplication W/art: Before Android 4.1, method int 安卓.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in 安卓.widget.ListView
07-10 18:31:12.738 15628-15628/com.example.amir.myapplication I/HwSecImmHelper: mSecurityInputMethodService is null
有人能帮忙吗
编辑
我的设备上没有外部存储器。华为ascend mate 7上没有sd卡。我只是在/res/raw文件夹中有一个mp3文件,我想在按下按钮时播放它。我参加了一门udacity课程,这是其中一个测验。当我看到解决方案时,代码就是我提供的,但我不能播放声音。我的意思是,我已经在我的安卓 studio上复制并粘贴了代码,但对我来说,它不起作用
解决方案:
在编辑代码之后,我找到了答案。我犯了个愚蠢的错误。暂停和播放有两个听者,但我给他们取了相同的名字。第二个监听器应该在暂停按钮上,而不是播放按钮pauseBtn。setOnClickListener
# 1 楼答案
你在aroom有档案吗? 你在舱单上申报过许可吗