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

    }

  • 相关阅读:
    Codeforces758C
    Codeforces758B
    CodeForces758A
    数据库实习
    数据结构实习-迷宫(基于Qt实现)
    CodeForces757B
    CodeForces757A
    HDU3790
    数据结构实习
    Codeforces374B
  • 原文地址:https://www.cnblogs.com/zhwl/p/2134899.html
Copyright © 2011-2022 走看看