Android:如何使用AndroidCameraAPI检测视频大小?
创始人
2024-10-13 16:30:17
0

使用Android Camera API检测视频大小的步骤:

步骤1:创建一个类来处理提取视频文件的信息和元数据。

public class VideoUtils {
 
    public static BitmapFactory.Options getVideoDimensions(String videoPath) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        MediaPlayer mp = MediaPlayer.create(context, Uri.parse(videoPath));
        int height = mp.getVideoHeight();
        int width = mp.getVideoWidth();
        return options;
    }
}

步骤2:添加权限到AndroidManifest.xml文件,以便访问存储和摄像头。



步骤3:在Activity中调用VideoUtils类中的方法来获取视频的大小。

public class MainActivity extends AppCompatActivity {

    private static final int REQUEST_VIDEO_CAPTURE = 1;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        Button recordButton = findViewById(R.id.record_button);
        recordButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dispatchTakeVideoIntent();
            }
        });
    }
 
    private void dispatchTakeVideoIntent() {
        Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
        }
    }
 
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
            Uri videoUri = data.getData();
            String path= videoUri.getPath();
            BitmapFactory.Options dimensions = VideoUtils.getVideoDimensions(path);
            int height = dimensions.outHeight;
            int width = dimensions.outWidth;
        }
    }
}

这样就可以通过使用Android Camera API检测视频大小了。

相关内容

热门资讯

智星德州插件怎么下载!hhpo... 智星德州插件怎么下载!hhpoker德州真的假的(透视)app-本来分享是真的挂1、操作简单,无需智...
透视专业!wepokerplu... 透视专业!wepokerplus辅助(透视)wpk透视是真的吗,教程教材(有挂攻略)-哔哩哔哩1、每...
WePOker有没有透视方法!... WePOker有没有透视方法!aapoker怎么设置提高好牌几率(透视)技巧-总是了解真的是有挂1、...
透视揭露!wepokerplu... 透视揭露!wepokerplus开挂(透视)wpk透视最怕三个东西,教程法子(有挂头条)-哔哩哔哩1...
hhpkoer辅助挂是真的吗!... hhpkoer辅助挂是真的吗!wepoker辅助透视软件(透视)方法-其实专业存在有挂在进入hhpk...
透视关于!hhpkoer辅助器... 透视关于!hhpkoer辅助器视频(透视)hhpoker为什么一直输,教程教材(有挂头条)-哔哩哔哩...
aapoker插件!cloud... aapoker插件!cloudpoker怎么开挂(透视)软件-真是科普是真的挂1、这是跨平台的clo...
透视科普!来玩德州破解器(透视... 透视科普!来玩德州破解器(透视)wepoker透视有用吗,教程学习(有挂助手)-哔哩哔哩1、不需要A...
hhpoker德州透视!pok... hhpoker德州透视!pokemmo手机脚本(透视)app-本来开挂真的是有挂1、完成pokemm...
透视教你!werplan透视挂... 您好,pokemmo辅助官网这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】...