android 怎样获取videoView的点击事件

 我来答
huanglenzhi
推荐于2016-06-08 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
采纳数:117538 获赞数:517201
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。

向TA提问 私信TA
展开全部
  xxxvideo.java
  
  public class RemoteVideo extends Activity {
  private String path = "";
  private String textUrl = "";
  private VideoView mVideoView;
  private static int i = 0;
  private int width;
  private int heigh;
  private Dialog dialog;
  
  private Handler mHandler = new Handler();
  public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  
  Bundle bundle = this.getIntent().getExtras();
  
  DisplayMetrics dm = new DisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(dm);
  width=dm.widthPixels;
  heigh=dm.heightPixels;
  textUrl = bundle.getString("url");
  if(width/heigh>0)
  {
  setContentView(R.layout.videoview);
  
  path = bundle.getString("widthurl");
  Log.i("mp4", "heng"+path);
  }
  if(width/heigh==0)
  {
  setContentView(R.layout.view);
  
  path = bundle.getString("heighturl");
  Log.i("mp4", "shu"+path);
  }
  
  dialog=ProgressDialog.show(this, "视频加载中...", "请您稍候");
  mVideoView = (VideoView) findViewById(R.id.surface_view);
  mVideoView.setVideoPath(path);
  MediaController controller = new MediaController(this);
  mVideoView.setMediaController(controller);
  mVideoView.requestFocus();
  mVideoView.setOnPreparedListener(new OnPreparedListener() {
  
  //@Override
  public void onPrepared(MediaPlayer mp) {
  mVideoView.setBackgroundColor(Color.argb(0, 0, 255, 0));
  dialog.dismiss();
  }
  });
  
  mVideoView.setOnCompletionListener(new OnCompletionListener() {
  //@Override
  public void onCompletion(MediaPlayer mp) {
  Toast.makeText(RemoteVideo.this, "video play finished!", Toast.LENGTH_LONG)
  .show();
  }
  });
  controller.setOnTouchListener(new View.OnTouchListener() {
  public boolean onTouch(View v, MotionEvent event) {
  return true;
  }
  });
  
  }
  
  
  @Override
  protected void onResume() {
  super.onResume();
  mVideoView.seekTo(i);
  mVideoView.start();
  }
  @Override
  protected void onStop() {
  super.onStop();
  mVideoView.pause();
  i = mVideoView.getCurrentPosition();
  }
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
  finish();
  return true;
  }
  return false;
  }
  }
  
  说明:
  1. VideoView可接收本地和远程的视频源并解码;
  2. MediaController为videoview的控制条类;
  3. bundle获取intent传过来的视频路径;
  
  二、videoview.xml
  <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http。//schemas。android。com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="fill_parent"
  android:gravity="left" android:orientation="horizontal">
  <VideoView android:id="@+id/surface_view"
  android:layout_width="176px" android:layout_height="132px"
  android:layout_gravity="left" />
  <WebView android:id="@+id/web_openonline"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
  </LinearLayout>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式