Search code examples
androidmedia-playerandroid-videoview

How to play Video from application cache in android


I want to play video file from android cache folder using the following code :

String cacheDir = getApplicationContext().getCacheDir().getAbsolutePath();
File outFile = new File(cacheDir, "intro.mp4");
vvIntro.setVideoPath(cacheDir+"/intro");
vvIntro.start();

But I got error :

07-05 20:14:21.896: E/MediaPlayer(1251): error (1, -2147483648)
07-05 20:14:21.928: I/Choreographer(1251): Skipped 79 frames!  The application may be doing too much work on its main thread.
07-05 20:14:22.186: D/gralloc_goldfish(1251): Emulator without GPU emulation detected.
07-05 20:14:22.496: E/MediaPlayer(1251): Error (1,-2147483648)
07-05 20:14:22.496: D/VideoView(1251): Error: 1,-2147483648

where the file is already exists and the required persimmon as show below : enter image description here


Solution

  • You create a File object pointing to your MP4 file, then totally ignore that File object and provide an invalid path to vvIntro. Instead, try:

    File outFile = new File(getCacheDir(), "yourVideoName.mp4");
    vvIntro.setVideoPath(outFile.getAbsolutePath());
    vvIntro.start();
    

    and see if that helps.