首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >音频文件在android中不播放。

音频文件在android中不播放。
EN

Stack Overflow用户
提问于 2017-07-10 14:05:07
回答 2查看 73关注 0票数 0

我有一个android应用程序,有两个按钮,播放按钮和暂停按钮。如果按下play按钮,则应该启动mp3文件。暂停按钮将暂停音乐。这是我的代码:

代码语言:javascript
复制
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();
        }
    });
}
}

这是我的逻辑猫:

代码语言:javascript
复制
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 android.app.HwCustHwWallpaperManagerImpl
07-10 18:31:12.204 15628-15628/com.example.amir.myapplication W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-10 18:31:12.336 15628-15628/com.example.amir.myapplication I/HwCust: Constructor found for class android.widget.HwCustTextViewImpl
07-10 18:31:12.345 15628-15628/com.example.amir.myapplication I/HwCust: Constructor found for class android.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 android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
07-10 18:31:12.738 15628-15628/com.example.amir.myapplication I/HwSecImmHelper: mSecurityInputMethodService is null

有人能帮忙吗?

编辑

我的设备上没有外部存储器。华为提升伴侣7,上面没有sd卡。我只是在/res/raw文件夹中有一个mp3文件,我想在按下按钮时播放它。我参加了一个udacity课程,这是一个测试。当我看到解决方案时,代码是我提供的,但我不能播放声音。我的意思是,我在我的android工作室复制并粘贴了代码,但对我来说,它不起作用。

解决方案:

在编辑了代码之后,我找到了答案。我犯了个愚蠢的错误。有两个监听器用于暂停和播放,但我将它们命名为相同的名称。第二个侦听器应该处于暂停按钮,而不是播放按钮pauseBtn.setOnClickListener。

EN

回答 2

Stack Overflow用户

发布于 2017-07-10 14:09:23

你在"aroom“有什么档案吗?你对清单有什么许可吗?

票数 1
EN

Stack Overflow用户

发布于 2017-07-10 14:18:01

如果从卡(如SD卡)读取mp3文件,则很可能需要声明运行时权限。您需要的关于运行时权限的所有信息都可以在这里找到:

https://developer.android.com/training/permissions/requesting.html

还要确保清单中也有静态权限,如下所示:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45014161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档