How to use android mediaplayer on motionevent -


I am trying to set a sound for my game, but the last error on the line is MediaPlayer mp = Make MediaPlayer (this, no suggestion? Thx

  @override public boolean on touch event (motivation event event) {int x_aux = (int) (event.getax) / (this gatewidth () / X)); Int y_aux = (int) (event.getY () / (this.getHyight () / y)); Drawing (x_aux, y_aux); Final Media Player MP = Media PlayerCredit (this, R.A.MOVO); SetOnClickListener (New View.OnClickListener () {public void onClick (see v) {mp.start ();}}); Return super Tonentange (event); }  

create (...) method Media Player is required as the first parameter context The problem is that your game class is a view (which is context Does not extend) so that this can be used for the first parameter. T work.

You can try to keep the context of context which is given in the constructor's private sector under private paint canneta; Add one for context . Example ...

  Public category games expand {private cell [] [] singlesquare = null; Int x = 3; Int y = 3; Private Int L; Private int a; Private boolean whatdrawn = false; Private Ind player = 3; Private paint canata; Personal reference references; // Add this line  

Then the example passed in the constructor in reference for example ...

  public Game (Reference Reference) {Super (Reference); This.context = context; // Add this line  

Then when you use Mediaplayer ...

  Final MediaPlayer mp = MediaPlayer When creating create (context, r.  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -