android-为mediaplayer导入原始mp3资源

android-为mediaplayer导入原始mp3资源,第1张

概述我正在尝试使用以下代码播放一个简单的mp3文件:packageswalehm.android.examples.myTest1;importswalehm.android.examples.myTest1.R;importandroid.app.Activity;importandroid.content.Context;importandroid.media.MediaPlayer;importandroid.os.Bundle;importan

我正在尝试使用以下代码播放一个简单的mp3文件:

package swalehm.androID.examples.myTest1;import swalehm.androID.examples.myTest1.R;import androID.app.Activity;import androID.content.Context;import androID.media.MediaPlayer;import androID.os.Bundle;import androID.Widget.TextVIEw;public class myTest1Main extends Activity {    Context context;   public MediaPlayer mp = MediaPlayer.create(this, R.raw.sound1);    /** Called when the activity is first created. */    @OverrIDe    public voID onCreate(Bundle savedInstanceState)     {        super.onCreate(savedInstanceState);        TextVIEw tv = new TextVIEw(this);        tv.setText("Hello, AndroID");        setContentVIEw(tv);        mp.start();    }}

我在“ res”文件夹中添加了一个名为“ raw”的文件夹,并且文件sound1.mp3在其中.

我检查了R.java.该文件中确实存在命名资源sound1.但是,当
创建它时,出现错误,提示无法解析sound1或不是字段.我浏览了论坛,并看到了从imprts删除androID.R的建议.现在我得到一个错误说:

对于类型myTest1Main,未定义方法MediaPlayer(myTest1Main,int).

解决方法:

它应该是:

public MediaPlayer mp = MediaPlayer.create(this, R.raw.sound1);
总结

以上是内存溢出为你收集整理的android-为mediaplayer导入原始mp3资源全部内容,希望文章能够帮你解决android-为mediaplayer导入原始mp3资源所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1071405.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存