Android-VR 支持流媒体

Google对vr支持非常速度,从0.7版本开始关注gvr-Android-sdk,这个版本还是比较初级,还只能支持图片,本地视频,如果你选择一个remote视频,就会报io异常,看了下源码,还没对远程视频做支持。
不过2周时间就对远程视频支持了,可以使用http访问视频地址,我赶紧尝试了下,发现还是坑,只是对mp4等一些视频格式支持,老板要的是流媒体啊,对m3u8不支持怎么是好,赶紧去github提问,很快就收到回复,项目在集成EXOplayer,做个视频的都知道,这个项目也是Google开源的,对流媒体很好的支持,看到了希望。
又等了大概一个时间,0.8版本出来了,赶紧尝试,果然流媒体支持了,Google就是不一样。

接下来使用Google官方的实例sdk-simplevideowidget,去播放随意找来的一个m3u8格式视频

SimpleVrVideoActivity中:

  private void handleIntent(Intent intent) {
        // Determine if the Intent contains a file to load.
        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            Log.i(TAG, "ACTION_VIEW Intent received");

            fileUri = intent.getData();
            if (fileUri == null) {
                Log.w(TAG, "No data uri specified. Use \"-d /path/filename\".");
            } else {
                Log.i(TAG, "Using file " + fileUri.toString());
            }
            //修改支持格式为 FORMAT_HLS 流媒体
            videoOptions.inputFormat = Options.FORMAT_HLS;
        } else {
            Log.i(TAG, "Intent is not ACTION_VIEW. Using the default video.");
            fileUri = null;
        }

        // Load the bitmap in a background thread to avoid blocking the UI thread. This operation can
        // take 100s of milliseconds.
        //把url直接转为uri传入Task 
        loadTask(Uri.parse("http://cache.utovr.com/s1oc3vlhxbt9mugwjz/L2_1920_3_25.m3u8"));
    }

一是格式修改为hls;

 videoOptions.inputFormat = Options.FORMAT_HLS;

二是把本地连接修改为自己的远程url

  loadTask(Uri.parse("http://cache.utovr.com/s1oc3vlhxbt9mugwjz/L2_1920_3_25.m3u8"));
 class VideoLoaderTask extends AsyncTask<Pair<Uri, Options>, Void, Boolean> {
        @Override
        protected Boolean doInBackground(Pair<Uri, Options>... fileInformation) {
            try {
                if (fileInformation == null || fileInformation.length < 1
                        || fileInformation[0] == null || fileInformation[0].first == null) {
                    videoWidgetView.loadVideoFromAsset("congo.mp4");
                } else {
                //remote视频还要设置下fileInformation,这个没啥好说的,根据API使用
                    videoWidgetView.loadVideo(fileInformation[0].first, fileInformation[0].second);
                }
            } catch (IOException e) {
                // An error here is normally due to being unable to locate the file.
                loadVideoStatus = LOAD_VIDEO_STATUS_ERROR;
                // Since this is a background thread, we need to switch to the main thread to show a toast.
                videoWidgetView.post(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(SimpleVrVideoActivity.this, "Error opening file. ", Toast.LENGTH_LONG).show();
                    }
                });
                Log.e(TAG, "Could not open video: " + e);
            }

            return true;
        }
    }

就改了这几个地方,在线视频播放起来了,vr开发是不是很简单,要搞清楚原理,后续分析。

实例源码下载

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值