读sd卡中的mp4文件的权限
代码
fun showVideo() { // 比如显示sdcard对应app的data中的kongfu.mp4 val video: String = getExternalFilesDir("")!!.getAbsolutePath() + "/kongfu.mp4" val file: File = File(video) if (!file.exists()) { Log.e(TAG, "file:${video} not exists") return } lifecycleScope.launch(Dispatchers.Main) { val firstframe = getFirstframeDrawable(video) if (firstframe != null) { // iv_first_frame是一个ImageView iv_first_frame.setVisibility(View.VISIBLE) iv_first_frame.setImageBitmap(firstframe) } } } private suspend fun getFirstframeDrawable(url: String): Bitmap? { val mmr = MediametadataRetriever() Log.d(TAG, "video_url = $url") return try { mmr.setDataSource(url) mmr.frameAtTime } catch (e: Exception) { e.printStackTrace() null } }可能出错点
如果这么调 mmr.setDataSource(url, HashMap())
会提示如下错误:
android java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
作者:帅得不敢出门
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)