我在此行 MediaPlayer.create(context,R.raw.music); 中收到有关“上下文”和“原始”的红线错误消息;在创建一个简单的媒体播放器应用程序时(音乐位于 /res/raw 文件夹中)。请帮助..这是完整的代码..
package com.example.mymedia;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.music);
mediaPlayer.start(); // no need to call prepare(); create() does that for you
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}