Search code examples
androidandroid-videoview

Can't play video in VideoView - why?


I am trying to play a video in VideoView in android but it always gives ( 1 -2147483648 ) error.

At first, I tried to play from URL, it didn't work so I downloaded the video, saved it on the raw folder and tried to play but it is still not working. when I googled the error ( 1 -2147483648 ), it says that this error occurs due to issues like incorrect URL or incompatible format but the video is .mp4 with the H264 codec. What else should I consider in order to play the video?

//activity

video_view.setMediaController(MediaController(context))

    val videoPath="android.resource://" + context!!.packageName+ "/" + R.raw.howappvideo
    video_view.setVideoURI(Uri.parse(videoPath))
    video_view.requestFocus()
    video_view.setOnPreparedListener {
        Log.i("SeeAllFragment","video is prepared")
        try{
            video_view.start()
        }catch (e:Exception){
            Log.i("SeeAllFragment","error while playing ${e.printStackTrace()}")
        }
    }
    video_view.setOnCompletionListener { mp ->
        toast("video completed")
        mp!!.release()
    }
    video_view.setOnErrorListener { mp, what, extra ->
        Log.i("SeeAllFragment","error while loading video $what $extra ")
        true
    }

Solution

  • it says that this error occurs due to issues like incorrect URL or incompatible format but the video is .mp4 with the H264 codec.

    => Reason being is VideoView is not that much powerful and extensible, in terms of codecs and other features.

    Rather I would suggest going with ExoPlayer library.

    There are multiple things why VideoView is failed to play video, one of the reasons being is when you record using other devices like iPhone, Camcorder, etc. They have a different format of video which might not be supported, also codec might not be supported. In this case, when we are developing solutions and having android/iPhone/TV or other mediums involved, we implement a code over backend for maintaining a single codec and that's how we maintain the compatibility with all the devices.