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

    }

  • 相关阅读:
    前后端交互, 安装drf, restful接口规范, pycharm断点调试
    django中文设置, axios, CORS, 全局js配置, Vue配置jq + bs
    js原型, Vue项目环境搭建, Vue项目目录结构, Vue项目生命周期, 小组件使用, 全局样式, 路由跳转, 组件的生命周期钩子, 路由传参
    Vue组件
    Vue表单指令, 条件指令, 循环指令, 成员
    question1 赋值运算操作符
    CH15 面向对象程序设计
    CH12 动态内存
    CH11 关联容器
    CH10 泛型算法
  • 原文地址:https://www.cnblogs.com/zhwl/p/2134899.html
Copyright © 2011-2022 走看看