"Android development VR combat" two. Play 360° Panorama video

Source: Internet
Author: User

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 do you develop VR apps 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 the load Settings **/Vrvideoview.options Options =NewVrvideoview.options (); Options.inputtype = VrVideoView.Options.TYPE_STEREO_OVER_UNDER;/** * Set Load monitor * /Vr_video_view.seteventlistener (NewVrvideoeventlistener () {/** * Video playback Complete callback */            @Override             Public void oncompletion() {Super. Oncompletion ();/** playback is complete, jump to start replay **/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 ()"); }/** * Load VR video failure callback * @param errormessage */            @Override             Public void Onloaderror(String errormessage) {Super. Onloaderror (ErrorMessage); LOG.D (TAG,"Onloaderror ()->errormessage="+ errormessage); }/** * Load VR Video success callback */            @Override             Public void onloadsuccess() {Super. onloadsuccess ();/** Set callback after successful loading **/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, that is, horizontal screen split screen mode * @p Aram NewDisplayMode mode * /            @Override             Public void ondisplaymodechanged(intNewDisplayMode) {Super. ondisplaymodechanged (NewDisplayMode); LOG.D (TAG,"Onloaderror ()->newdisplaymode="+ NewDisplayMode); }        });Try{/** loading 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 to 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); }/** * Set Play pause * * @param isplay Play Pause */    Private void Setisplay(BooleanIsplay) { 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° Panorama video

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.