soundPool.load 上下文问题

Issue with soundPool.load Context

我的应用程序中有一个调用异步任务的按钮。 此异步任务应在每个 ProgressUpdate 上播放音频文件。 到目前为止我想出了很多,但我坚持这个:

我打电话给

        this.strengthSound[0] = this.soundPool.load(this, R.raw.strength0,1);
        this.strengthSound[1] = this.soundPool.load(this, R.raw.strength1,1);
        this.strengthSound[2] = this.soundPool.load(this, R.raw.strength2,1);
        this.strengthSound[3] = this.soundPool.load(this, R.raw.strength3,1);
        this.strengthSound[4] = this.soundPool.load(this, R.raw.strength4,1);

用 strengthx.mp3 填充数组。

无论如何:我在加载语句中收到 "this" 错误:

Error:(165, 57) error: incompatible types: AIM_start.start_AIM cannot be converted to Context

这个 soundPool.load(Context, ResourceID, ..) 我必须使用什么上下文?

提前感谢您的帮助...:)

private Context mContext;

onCreate(...) {
    mContext = this;
}


// inside your AsyncTask 
...

    onProgressUpdate(int progress) {
      this.strengthSound[0] = this.soundPool.load(mContext, R.raw.strength0,1);
      ...
    }

我忘记了 AsyncTasks 的实际方法签名,但这是基本的概要。您在滥用 this

this 在你的 activity 和 this 在你的 AsyncTask 是不同的。 AsyncTask 中的 this 指的是它自己,即 AsyncTask,但是 onCreate 中的 this 指的是(再次)它自己,即 Activity 本身。

不确定这是否有帮助,但请随时详细说明评论:)