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检测视频大小了。

相关内容

热门资讯

安装程序教程!aapoker脚... 安装程序教程!aapoker脚本,aapoker怎么控制牌,必胜教程(有挂神器)是一款可以让一直输的...
实测交流!聚星ai辅助工具下载... 实测交流!聚星ai辅助工具下载,wpk安卓下载辅助,科技教程(有挂透视)1、点击下载安装,微扑克wp...
必看攻略!wepoker透视a... 必看攻略!wepoker透视app下载,wpk模拟器,2025新版教程(有挂透明);玩家必备必赢加哟...
总算清楚!hhpoker到底可... 总算清楚!hhpoker到底可以作弊码,pokemmo手机脚本辅助器,2025新版教程(有挂方法);...
记者爆料!约局吧能不能开挂,w... 此外,数据分析德州(约局吧能不能开挂)辅助神器app还具备辅助透视行为开挂功能,通过对客户约局吧能不...
技术分享!wepoker辅助器... 技术分享!wepoker辅助器官方,sohoo辅助,软件教程(有挂技巧)准备好在wepoker辅助器...
信息共享!cloudpoker... 这是一款非常优秀的cloudpoker怎么开挂 ia辅助检测软件,能够让你了解到cloudpoker...
推荐十款!wepoker透视脚... 推荐十款!wepoker透视脚本视频,hhpoker买挂,安装教程(有挂神器);科技安装教程;136...
科普攻略!aapoker辅助怎... 科普攻略!aapoker辅助怎么用,hhpoker有后台操作吗,安装教程(有挂技巧)1、点击下载安装...
玩家必看教程!竞技联盟破解版最... 玩家必看教程!竞技联盟破解版最新版,云扑克有透视吗,技巧教程(有挂辅助)这是由厦门游乐互动科技有限公...