首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Android中添加MediaPlayer对象(宋体)?

在Android中添加MediaPlayer对象(宋体)?
EN

Stack Overflow用户
提问于 2015-01-01 23:06:55
回答 1查看 100关注 0票数 0

我正试着在我的第一个简单的应用程序中开始简短的歌曲。一切都正常工作,直到我添加了"ourSong“对象,然后我在模拟器”不幸地MyApp停止了“上得到了错误,正如我说的,如果我评论"ourSong.start()"+ "ourSong.release()”,这个应用程序就能工作。

代码语言:javascript
复制
package com.example.helloworld;

import java.util.Timer;

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 savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);

		ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
		ourSong.start();

		Thread timer = new Thread() {
			public void run() {
				try {
					sleep(5000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				} finally {
					Intent openStartingPoint = new Intent(
							"com.example.helloworld.MAINACTIVITY");
					startActivity(openStartingPoint);
				}
			}
		};

		timer.start();
	}

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

}

我很感谢你的帮助

EN

回答 1

Stack Overflow用户

发布于 2015-01-01 23:43:30

确保您的“原始”文件夹位于"res“中。

要了解更多细节,请看一下

在真正的设备上试一试!

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

https://stackoverflow.com/questions/27735536

复制
相关文章

相似问题

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