Reprint Please specify source: http://blog.csdn.net/linglongxin24/article/details/53924006
This article is from "Dylanandroid's blog"
"Android development VR combat" two. Play 360° Panorama video
VR is virtual reality reality. Virtual reality technology is a kind of computer simulation system that can create and experience virtual world. It uses computer to generate a simulation environment is a multi-source information Fusion Interactive Three-dimensional dynamic visual and physical behavior of the system simulation to immerse users into the environment.
So, how to develop VR app in Android? We use the Open Source SDK provided by Google to realize the functionality of a 360° panorama video
I. SDK dependencies for the introduction of Google VR in Build.gradle
‘com.google.vr:sdk-videowidget:1.10.0‘
Two. Note the minimum supported SDK
minSdkVersion 19 targetSdkVersion 25
Three. Interface Layout file
<?xml version= "1.0" encoding= "Utf-8"?><LinearLayout xmlns:android="Http://schemas.android.com/apk/res/android" Xmlns:tools="Http://schemas.android.com/tools" Android:id="@+id/activity_main" Android:layout_width="Match_parent" Android:layout_height="Match_parent" android:orientation="Vertical" Android:paddingbottom="@dimen/activity_vertical_margin" Android:paddingleft="@dimen/activity_horizontal_margin" Android:paddingright="@dimen/activity_horizontal_margin" Android:paddingtop="@dimen/activity_vertical_margin" Tools:context="Cn.bluemobi.dylan.vrdevelopvideo.MainActivity"> <TextViewandroid:layout_width="Wrap_content"android:layout_height= "Wrap_content" Android:text="Android Development VR360 Panorama video" /> <com.google.vr.sdk.widgets.video.VrVideoViewandroid:id="@+id/vr_video_view" android:layout_width="Match_parent"android:layout_height="250DP" > </com.google.vr.sdk.widgets.video.VrVideoView> <linearlayoutandroid:layout_width="Match_parent"android:layout_height ="Wrap_content"android:orientation="Horizontal"> <imagebutton android:id< /span>= "@+id/play_toggle" android:layout_width= "0DP" android:layout_height = "wrap_content" android:layout_weight =" 1 " android:background =" @android: Co Lor/transparent " android:paddingstart =" 0DP " android:src = "@drawable/pause" /> <SeekBar android:id="@+id/seek_bar" style="?Android:attr/progressbarstylehorizontal " Android:layout_width="0DP" Android:layout_height="32DP" Android:layout_weight="8"/> <imagebutton android:id< /span>= "@+id/volume_toggle" android:layout_width = "0DP" android:layout_height = "wrap_content" android:layout_weight =" 1 " android:background =" @android: Color/transparent " android:paddingstart =" 0d P " android:paddingtop =" 4DP " android:src = "@drawable/volume_on" /> </linearlayout></linearlayout>
Four. Load 360° Panorama video
/** * Load 360-degree panorama video */ Private void Load360video() {Vr_video_view = (Vrvideoview) Findviewbyid (R.id.vr_video_view); Seek_bar = (SeekBar) Findviewbyid (R.id.seek_bar); Volume_toggle = (ImageButton) Findviewbyid (R.id.volume_toggle); Play_toggle = (ImageButton) Findviewbyid (R.id.play_toggle);/** setting load Settings **/Vrvideoview.options Options =NewVrvideoview.options (); Options.inputtype = VrVideoView.Options.TYPE_STEREO_OVER_UNDER;/** * Set Load monitoring * /Vr_video_view.seteventlistener (NewVrvideoeventlistener () {/** * Video playback Complete callback */ @Override Public void oncompletion() {Super. Oncompletion ();/** after playback, jump to start and play again **/Vr_video_view.seekto (0); Setisplay (false); LOG.D (TAG,"Oncompletion ()"); }/** * Load callback for each frame of video */ @Override Public void Onnewframe() {Super. Onnewframe (); Seek_bar.setprogress ((int) vr_video_view.getcurrentposition ()); LOG.D (TAG,"Onnewframe ()"); }/** * Click on VR video callback */ @Override Public void OnClick() {Super. OnClick (); LOG.D (TAG,"OnClick ()"); }/** * Loading VR video failure callback * @param errormessage */ @Override Public void Onloaderror(String errormessage) {Super. Onloaderror (ErrorMessage); LOG.D (TAG,"Onloaderror ()->errormessage="+ errormessage); }/** * Loading VR Video Success Callback */ @Override Public void onloadsuccess() {Super. onloadsuccess ();/** Set callback after loading success **/Seek_bar.setmax ((int) vr_video_view.getduration ()); LOG.D (TAG,"Onnewframe ()"); }/** * Display Mode change callback * 1. Default * 2. Full Screen mode * 3.VR viewing mode. Horizontal split Screen mode * @param newDisplayMode mode * / @Override Public void ondisplaymodechanged(intNewDisplayMode) {Super. ondisplaymodechanged (NewDisplayMode); LOG.D (TAG,"Onloaderror ()->newdisplaymode="+ NewDisplayMode); } });Try{/** onboarding VR video **/Vr_video_view.loadvideofromasset ("Congo.mp4", options); }Catch(IOException e) {E.printstacktrace (); }/** Set the sound button tap Listen **/Volume_toggle.setonclicklistener (NewView.onclicklistener () { Public void OnClick(View v) {setismuted (!ismuted); } });/** Set Play pause button tap Listen **/Play_toggle.setonclicklistener (NewView.onclicklistener () { Public void OnClick(View v) {Setisplay (!isplay); } });/** Setting progress bar drag monitoring **/Seek_bar.setonseekbarchangelistener (NewSeekbar.onseekbarchangelistener () {/** * Progress bar drag Change listening * @param seekBar Drag Bar * @param Progress Progress * @param Whether the Fromuser is manually operated by the user */ @Override Public void onprogresschanged(SeekBar SeekBar,intProgressBooleanFromuser) {if(Fromuser) {/** Adjust video progress **/Vr_video_view.seekto (progress); } }@Override Public void Onstarttrackingtouch(SeekBar SeekBar) { }@Override Public void Onstoptrackingtouch(SeekBar SeekBar) { } }); }/** * Set the sound switch * * @param ismuted Switch */ Private void setismuted(Booleanismuted) { This. ismuted = ismuted; Volume_toggle.setimageresource (ismuted? R.drawable.volume_off : R.drawable.volume_on); vr_video_view.setVolume(isMuted ? 0.0f : 1.0f); } /** * 设置播放暂停 * * @param isPlay 播放暂停 */ private void setIsPlay(boolean isPlay) { this.isPlay = isPlay; play_toggle.setImageResource(isPlay ?R.drawable.pause: R.drawable.play ); if(isPlay){ vr_video_view.playVideo(); }else{ vr_video_view.pauseVideo(); } }
Five. GitHub
"Android development VR combat" two. Play 360& #176; Panorama video