我需要在我的视图中调用MediaPlayer

时间:2011-12-17 10:45:17

标签: java android eclipse

在扩展View的类中,有没有办法调用MediaPlayer?

我已经在我的Activity类上成功地使用了mediaplayer。

如果不可能,有没有办法可以调用方法从我的View类开始在我的Activity类中传输音频?

机器人。

public class RealPlayView extends View {
// call objects
private Background background;
private Grid grid;
private Box[] box = new Box[30];
private Paint[] paint = new Paint[30];
private UpdateHandler updatehandler;
private Handler invalidatehandler;
private ColorFilter filter;

// sound variables
private RealPlayActivity realplayactivity;

// variables
public int lineNum = 0;
public int boxValue = 3;
public int gameSpeed = 250;
public int controlMove = 1;
public int controlSet = 1;
public boolean goRight;

// other variables regarding plain function
public int setX1 = 100;
public int setX2 = 100;
public int setX3 = 100;
public int endGame = 0;

// variables regarding to checker
public int X1;
public int X2;
public int X3;
public int X4;
public int X5;
public int X6;
public int X4D;
public int X5D;
public int X6D;

public RealPlayView(Context context) {
    super(context);

    // call objects
    background = new Background(context, R.drawable.background);
    grid = new Grid(context, R.drawable.grid);
    updatehandler = new UpdateHandler();
    invalidatehandler = new Handler();
    filter = new PorterDuffColorFilter(0xffffcc33, PorterDuff.Mode.SRC_ATOP);
    }

1 个答案:

答案 0 :(得分:1)

尝试使用context

的make base
MediaPlayer mp_xmPlayer2 = MediaPlayer.create(context, R.raw.error );
mp_xmPlayer2.start();