Android超级简单的播放VR视频

26 篇文章 2 订阅
14 篇文章 1 订阅

项目引入:

最新版本:https://github.com/googlevr/gvr-android-sdk/releases

implementation 'com.google.vr:sdk-panowidget:1.30.0'
implementation 'com.google.vr:sdk-videowidget:1.30.0'

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.vr.sdk.widgets.video.VrVideoView
        android:id="@+id/vr_video"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <SeekBar
        android:id="@+id/seek_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp" />

</RelativeLayout>

代码:

public class VideoPlayerActivity extends AppCompatActivity {

    private VrVideoView vr_video;
    private SeekBar seekBar;
    private String url = "http://xxx.mp4";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_player);
        vr_video = findViewById(R.id.vr_video);
        seekBar = findViewById(R.id.seek_bar);

        vr_video.setEventListener(new VrVideoEventListener() {
            @Override
            public void onLoadSuccess() {
                super.onLoadSuccess();
                seekBar.setMax((int) vr_video.getDuration());
            }

            @Override
            public void onNewFrame() {
                super.onNewFrame();
                seekBar.setProgress((int) vr_video.getCurrentPosition());
            }
        });

        VrVideoView.Options options = new VrVideoView.Options();
        options.inputType = VrVideoView.Options.TYPE_MONO;
        options.inputFormat = VrVideoView.Options.FORMAT_DEFAULT;
        try {
            vr_video.loadVideo(Uri.parse(url), options);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    @Override
    protected void onResume() {
        super.onResume();
        vr_video.resumeRendering();
    }

    @Override
    protected void onPause() {
        super.onPause();
        vr_video.pauseRendering();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        vr_video.shutdown();
    }
}

在github上面找到了一种更简单的方法,可以直接通过mediaplay播放VR

https://github.com/ashqal/MD360Player4Android

//引入
implementation 'com.github.ashqal:MD360Player4Android:2.5.0'
//布局
<android.opengl.GLSurfaceView
        android:id="@+id/surface_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
mediaPlayer = MediaPlayer.create(this, R.raw.vr);
        mVRLibrary = MDVRLibrary.with(this)
                .displayMode(MDVRLibrary.DISPLAY_MODE_NORMAL)
                .interactiveMode(MDVRLibrary.INTERACTIVE_MODE_MOTION)
                .asVideo(surface -> {
                    mediaPlayer.setSurface(surface);

                })
                .build((GLSurfaceView) findViewById(R.id.surface_view));
        mediaPlayer.start();

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值