I want to play a video that is stored in the assets folder of my Android application. The following code works (meaning the video plays) on a newer API level (tested on 16) but not on level 6.

    String FILEPATH = "/data/data/com.example.test1/videoname.flv";    

    //GET VIDEO FROM ASSETS
    try {
        InputStream is = getAssets().open("videoname.flv");

        OutputStream os = new FileOutputStream(FILEPATH);

        byte[] buffer = new byte[50000];
        int bytesRead;

        while((bytesRead = is.read(buffer)) !=-1){
            os.write(buffer, 0, bytesRead);
        }
        is.close();
        os.flush();
        os.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    //SET VIDEO SOURCE AND PLAY VIDEO
    video_player_view = (VideoView) findViewById(R.id.video_view);
    video_player_view.setVideoPath(FILEPATH);
    video_player_view.start();

On API level 6, a message appears:

"Sorry, this video cannot be played"

How can I play a video from the assets folder also in the very low API levels?

Related posts

Recent Viewed