I seem to be running into a strange issue with MediaMetadataRetriever and FFmpegMediaMetadataRetriever.
I have a videoView from which I want to extract the last frame, and I am using MediaMetadataRetriever which needs to set a datasource.
However whenever I set this datasource with the same URI as the videoview, I get
java.lang.IllegalArgumentException: setDataSource failed: status = 0xFFFFFFFF
at wseemann.media.FFmpegMediaMetadataRetriever.setDataSource(Native Method)
Even if I hardcode the following:
retriever.setDataSource("android.resource://" + mActivity.packageName + "/" + R.raw.step3_r0man2
It still does nothing. However the videoview in question uses the exact same URL and has no problem playing the video
I've also tried the following:
retriever.setDataSource(context, url)
Same result.
This is all done within an android fragment in kotlin.
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)
}
}
}
}
Here are the dependencies:
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'
I've also followed: MediaMetadataRetriever setDataSource throws IllegalArgumentException
And nothing works :(
Not sure what's going on. Is there another way to get the last frame of a video, blur it with blurry, then set it to an imageview?
User contributions licensed under CC BY-SA 3.0