播放按钮点击一个视频文件 [英] Playing a video file on button click

查看:361
本文介绍了播放按钮点击一个视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我把这个codeS线进入按钮onClick事件那么它将给了​​我错误豪解决它。一行的错误MC =新的MediaController(本);,并错误是:
(构造的MediaController(新View.OnClickListener(){})是未定义)

 公共类TrialVideoActivity延伸活动{ 公众的MediaController MC;@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
  的setContentView(R.layout.main);最后的按钮播放=(按钮)findViewById(R.id.play);
  play.setOnClickListener(新OnClickListener(){
      公共无效的onClick(视图V){  VideoView VD =(VideoView)findViewById(R.id.surface_view);
  URI URI = Uri.parse(android.resource://+ getPackageName()+/\"+R.raw.lic);
  MC =新的MediaController(本);
  vd.setMediaController(MC);
  vd.requestFocus();
  vd.setVideoURI(URI);
  vd.start();      }
  });}

每当我播放的视频文件直接那么它会完美的工作,但每当我把它改成了按钮,点击它会显示上述错误。
plz帮助我。

还有一件事如何视频NAD的质量提高视频时,乳宁视频的声音确定,但影片内容的声音背后...缓冲b'coz


解决方案

  MC =新的MediaController(本);

在这一行要传递按钮点击的背景下,我认为你应该通过这里的您的活动上下文
为此,您应该声明的上下文

内部类,然后在 onCreat(),你shiuld通过

初始化;

私人上下文的背景下

  =背景下这一点;

和使用

  MC =新的MediaController(背景); //这是利用活动课的内容。

这是更好的解决问题的语境方式。

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...

解决方案

 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.

这篇关于播放按钮点击一个视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆