【问题标题】:Why does my android app crash after adding a sound using MediaPlayer为什么使用 MediaPlayer 添加声音后我的 android 应用程序崩溃
【发布时间】:2014-07-07 15:18:33
【问题描述】:

我一直在关注此视频教程 here,为应用启动时发生的 5 秒启动活动(?)添加声音。在使用视频中详细介绍的新声音添加编辑应用程序之前,该应用程序运行良好并显示存储在 R.layout.splash xml 文件中的图像

我的应用程序正在运行,并且代码与开始时视频中的代码几乎完全相同。但是,在观看此视频并进行建议的更改后,应用程序在显示图像或声音之前崩溃(在任何错误消息中都没有给出重要信息,只是应用程序已经崩溃)。

添加音频文件后,我确实再次清理了项目。 音频文件确实以 pikachu.mp3 的形式存在于 res/raw 文件夹中(这是一个短 3 秒的声音)。 我还尝试在没有 onPause 部分代码的情况下运行该应用程序,但它仍然会立即崩溃。我正在运行的代码如下,如果你能看一下并给我一些关于为什么应用程序不断崩溃的建议,我将不胜感激。谢谢。

package com.example.thenewbonston;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;

public class Splash extends Activity{

MediaPlayer ourSong;

@Override
protected void onCreate(Bundle TravisLoveBacon) {
    // TODO Auto-generated method stub
    super.onCreate(TravisLoveBacon);
    setContentView(R.layout.splash);
    ourSong = MediaPlayer.create(Splash.this, R.raw.pikachu);
    ourSong.start();
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);
            } catch (InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent openStartingPoint = new       Intent("com.example.thenewbonston.STARTINGPOINT");
                startActivity(openStartingPoint);
            }
        }
    };
    timer.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    ourSong.release();
    finish();
}


}

【问题讨论】:

  • 堆栈跟踪说明了什么
  • 什么是堆栈跟踪?
  • 假设它是 Eclipse 底部的一系列消息,这就是我所拥有的:[2014-07-07 18:02:57 - The New Bonston] 安装新 Bonston.apk.. . [2014-07-07 18:03:02 - 新邦斯顿] 成功! [2014-07-07 18:03:02 - The New Bonston] 在设备 emulator-5554 上启动活动 com.example.thenewbonston.Splash [2014-07-07 18:03:04 - The New Bonston] ActivityManager:开始:意图 { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.thenewbonston/.Splash }
  • 它会告诉您问题所在,否则我们无法帮助您
  • 查看 LogCat 输出的内容。这通常会为您提供一个有意义的例外,其中包含应该解释问题的详细信息。

标签: android eclipse audio android-activity crash


【解决方案1】:

也许你只需要清理和构建你的应用程序,你的代码看起来不错 (项目 > 在 Eclipse 中清理)

【讨论】:

  • 不抱歉,清洁没有帮助。我在发帖前试过了。不过,感谢您的宝贵时间!
  • 我在视频中看到他的 mp3 文件旁边有一个音符图标。当我查看我的文件时,它只有一个普通的文本文档外观符号;你认为这有关系吗?可能是 mp3 文件没有被识别?
  • 先生,我们需要比猜测更好地看到你的错误堆栈,它可能是不支持的文件格式
  • 错误堆栈是什么?在eclipse界面哪里可以找到呢?
  • 选择 DDMS(如果你没有找到它打开窗口 ---> 打开透视图 -->> DDMS)选择日志猫(如果你没有找到它窗口 ---> 显示视图 --> 日志cat),错误堆栈红线中的代码块
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-29
  • 1970-01-01
相关资源
最近更新 更多