您的位置:首页 > 移动开发 > Android开发

Android-VR 支持流媒体

2016-07-11 22:07 369 查看
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开发是不是很简单,要搞清楚原理,后续分析。

实例源码下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: