简体   繁体   English

是否在API级别低于7的情况下在Android的VideoView中播放资产中的视频?

[英]Play video from assets in VideoView in Android on API level <7?

I want to play a video that is stored in the assets folder of my Android application. 我想播放存储在我的Android应用程序资产文件夹中的视频。 The following code works (meaning the video plays) on a newer API level (tested on 16) but not on level 6. 以下代码在较新的API级别(在16上测试)上有效(意味着视频可以播放),但在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: 在API级别6上,出现一条消息:

"Sorry, this video cannot be played" “抱歉,这部影片无法播放”

How can I play a video from the assets folder also in the very low API levels? 如何在非常低的API级别下也从资产文件夹播放视频?

As @petey says, there's no need really to support anything below API 8. The bigger problem is that FLV was never supported natively and the support depended on the device and Flash plugin installation and the safest bet was to play the video in the WebView. 正如@petey所说,并不需要真正支持API 8以下的任何东西。更大的问题是,FLV本身不受支持,而支持取决于设备和Flash插件的安装,最安全的选择是在WebView中播放视频。

But since Google recently removed Flash plugin from the store and you can only install it manually from Adobe's website, you either need to stop using FLV or, money permitting, you should buy some of the player components that support the FLV format by themselves like Vitamio. 但是,由于Google最近从商店中删除了Flash插件,并且您只能从Adobe网站手动安装它,因此您要么需要停止使用FLV,要么在允许的情况下,应该购买一些支持FLV格式的播放器组件,例如Vitamio 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM