zoukankan      html  css  js  c++  java
  • android如何播放音视频【原】

    // 选取视频按钮单击事件
     public void click_xuanqushipin(View source) {

      Intent intent = new Intent();
      /* 开启Pictures画面Type设定为image */
      intent.setType("video/*");
      /* 使用Intent.ACTION_GET_CONTENT这个Action */
      intent.setAction(Intent.ACTION_GET_CONTENT);
      /* 取得相片后返回本画面 */
      startActivityForResult(intent, 3);

     }

    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      // 选取音频的返回值
      if (requestCode == 2) {
       //
       if (resultCode == RESULT_OK) {
        Uri uri = data.getData();
        //
        // toast = Toast.makeText(getApplicationContext(), "图片标题不能为空!",
        // Toast.LENGTH_LONG);
        // toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
        // toast.show();
        //
        Cursor cursor = getContentResolver().query(uri, null, null,
          null, null);
        cursor.moveToFirst();
        // String imgNo = cursor.getString(0); // 图片编号
        gj.imgPath = cursor.getString(1); // 图片文件路径
        String imgName = cursor.getString(2); // 图片文件名
        String imgSize = cursor.getString(3); // 图片大小

        gj.fileName = imgName;
        gj.fileSize = imgSize;
        // Log.e("uri", uri.toString());
        ContentResolver cr = this.getContentResolver();
        try {
         // 尝试将音频文件 赋值给videoView
         //
         final MediaController mediaController = new MediaController(this);
         VideoView videoView = (VideoView) findViewById(R.id.videoView1);
         videoView.setMediaController(mediaController);
         //videoView.setVideoPath(gj.imgPath);
         videoView.setVideoURI(uri);
         videoView.requestFocus();
         videoView.start();

         
        } catch (Exception e) {
         // TODO: handle exception
        }
       }
      }

    }

  • 相关阅读:
    事事浑不着意,总得有走心的地方
    Struts2框架概述
    java算法数据结构
    shell十三问(转)
    linux:将job放在后台执行的方法
    Python性能(转)
    python collections deque
    python中的参数传递和返回值
    python中的下划线
    python学习笔记glob模块
  • 原文地址:https://www.cnblogs.com/zhwl/p/2134899.html
Copyright © 2011-2022 走看看