Reputation: 33
Whenever I'll put this codes line into the button onClick event then it will gave me error ho to resolve it. The Error on a line of "mc = new MediaController(this); " and error is : ("The constructor MediaController(new View.OnClickListener(){}) is undefined")
public class TrialVideoActivity extends Activity {
public MediaController mc;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button play =(Button)findViewById(R.id.play);
play.setOnClickListener(new OnClickListener(){
public void onClick(View V){
VideoView vd = (VideoView) findViewById(R.id.surface_view);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"+R.raw.lic);
mc = new MediaController(this);
vd.setMediaController(mc);
vd.requestFocus();
vd.setVideoURI(uri);
vd.start();
}
});}
Whenever I played the video file directly then it will working perfectly but whenever I put it into the button click it will show the above error. plz help me.
And one more thing how to increasing quality of video nad the buffering b'coz when the video is runing sound of the video is ok but the video going behind the sound...
Upvotes: 0
Views: 3663
Reputation: 1598
mc = new MediaController(this);
on this line you are passing Context of Button click, I think you should pass here your Activity Context. For this you should declare a Context
Private Context context; inside Class and then inside onCreat() you shiuld initialize it by
context = this;
and use
mc = new MediaController(context); // this is using context of Activity Class.
this is better way to resolve Context problem.
Upvotes: 1