无论将什么设置为数据源kotlin,FFmpegMediaMetadataRetriever 和 MediaMetadataRetriever 都会崩溃,即使使用 videoview 测试了有效的 URI

问题描述

我似乎在使用 MediaMetadataRetriever 和 FFmpegMediaMetadataRetriever 时遇到了一个奇怪的问题。

我有一个 videoView,我想从中提取最后一帧,我正在使用 MediaMetadataRetriever,它需要设置数据源。

但是,每当我使用与视频视图相同的 URI 设置此数据源时,我都会得到

    java.lang.IllegalArgumentException: setDataSource Failed: status = 0xFFFFFFFF
        at wseemann.media.FFmpegMediaMetadataRetriever.setDataSource(Native Method)

即使我硬编码以下内容

retriever.setDataSource("android.resource://" + mActivity.packageName + "/" +  R.raw.step3_r0man2

它仍然什么都不做。但是,有问题的视频视图使用完全相同的 URL,播放视频没有问题

我还尝试了以下方法

retriever.setDataSource(context,url)

同样的结果。

这一切都在 kotlin 的 android 片段中完成。

open fun configureVideoPlayer() {
        videoUrl?.let { url ->
            vvStepVideo.setVideoURI(url)

            vvStepVideo.setonPreparedListener(MediaPlayer.OnPreparedListener { player ->
                val videoRatio = player.videoWidth / player.videoHeight.toFloat()
                val screenRatio = vvStepVideo.width / vvStepVideo.height.toFloat()
                val scaleX = videoRatio / screenRatio
                if (scaleX >= 1f) {
                    vvStepVideo.scaleX = scaleX
                } else {
                    vvStepVideo.scaleY = 1f / scaleX
                }
                if (!vvStepVideo.isPlaying) {
                    vvStepVideo.start()
                    player.isLooping = shouldLoopVideo
                    audioTrack?.let {
                        configureAudio(it,false)
                        val currentLocale = ConfigurationCompat.getLocales(resources.configuration)[0]
                        if (!currentLocale.toString().startsWith("en_")) {
                            player.setVolume(0.0f,0.0f)
                        }
                    }
                } else {
                    vvStepVideo.stopPlayback()
                }
            })

            if (!shouldLoopVideo) {
                vvStepVideo.setonCompletionListener { player ->
                    btnReplayVideo.visibility = View.VISIBLE
                    btnScanQRCode.visibility = View.VISIBLE
                    tvFirstScan.visibility = View.GONE
                    blur.visibility = View.VISIBLE

                    val retriever = FFmpegMediaMetadataRetriever()
                    retriever.setDataSource(url.toString())
                    //always crashes here ^
//                    val bitmap = retriever.getFrameAtTime(vvStepVideo.currentPosition.toLong() * 1000)
//
//                    Blurry.with(context).from(bitmap).into(blur)

                }
            }
        }
    }

这里是依赖项:

implementation 'jp.wasabeef:blurry:4.0.0'
implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-core:1.0.15'
implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-native:1.0.15'

我也关注了: MediaMetadataRetriever setDataSource throws IllegalArgumentException

没有任何效果:(

不知道发生了什么。有没有另一种方法可以获取视频的最后一帧,将其模糊化,然后将其设置为图像视图?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)