当前位置:   article > 正文

Go最新google vr 入门之制作简易的VR播放器及去除界面控制按钮,腾讯Golang开发面试凉凉_vrvideoview

vrvideoview

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以戳这里获取

做好如上配置之后,便可以写代码了。

在布局文件中添加播放器控件VrVideoView

<com.google.vr.sdk.widgets.video.VrVideoView

android:id=“@+id/video_view”

android:layout_width=“match_parent”

android:layout_height=“match_parent”/>

在Activity中找到控件,设置播放资源即可实现播放。

mVideoView = (VrVideoView) findViewById(R.id.video_view);

VrVideoView.Options option = new VrVideoView.Options();

try {

mVideoView.loadVideo(uri, option);

} catch (IOException e) {

e.printStackTrace();

}

到这我们的播放器就可以播放了,最基本的播放功能就已经实现了。不过这种太简陋了,我们的播放器应该有一些控制按钮,而且是VR播放器应该有VR模式才行,不能是简单的全屏就完了。

下面我们开始正式制作我们的简易版播放器:

activity_player.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

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”

tools:context=“com.qj.gvr_test.MainActivity”>

<com.google.vr.sdk.widgets.video.VrVideoView

android:id=“@+id/video_view”

android:layout_width=“match_parent”

android:layout_height=“match_parent”/>

<LinearLayout

android:id=“@+id/video_progress_container”

android:layout_width=“@dimen/y1000”

android:layout_height=“@dimen/y100”

android:layout_alignParentBottom=“true”

android:layout_centerHorizontal=“true”

android:layout_marginBottom=“@dimen/y100”

android:background=“@drawable/video_progress_shape”

android:visibility=“gone”>

<ImageView

android:id=“@+id/play”

android:layout_width=“@dimen/x90”

android:layout_height=“@dimen/y90”

android:layout_gravity=“center_vertical”

android:src=“@mipmap/stop”/>

<SeekBar

android:id=“@+id/video_progress”

style=“@style/Widget.AppCompat.ProgressBar.Horizontal”

android:layout_width=“@dimen/x600”

android:layout_height=“@dimen/y100”

android:layout_marginLeft=“@dimen/x_20”/>

<TextView

android:id=“@+id/video_duration”

android:layout_width=“@dimen/x240”

android:layout_height=“wrap_content”

android:layout_gravity=“center_vertical”

android:textColor=“@color/colorFFFFFF”/>

<ImageView

android:id=“@+id/video_vr”

android:layout_width=“@dimen/x90”

android:layout_height=“@dimen/x90”

android:layout_gravity=“center_vertical”

android:src=“@mipmap/icon_vr”/>

PlayerActivity

public class PlayerActivity extends Activity implements View.OnClickListener {

private VrVideoView mVideoView;

private String mUrl;

private TextView mVideoDuration;

private SeekBar mSeekBar;

private View mVideoPorgressContainer;

private String mTotalDuration;//视频总时长, 00:08格式

private ImageView mPlayView;

private boolean isPlaying;

private View mVideoVr;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_player);

Intent intent = getIntent();

mUrl = intent.getStringExtra(“url”);//上一个Activity传递过来的url播放地址

initView();

initData();

initListener();

}

@Override

protected void onNewIntent(Intent intent) {

setIntent(intent);

//TODO handleIntent

}

private void initView() {

mVideoView = (VrVideoView) findViewById(R.id.video_view);

mPlayView = (ImageView) findViewById(R.id.play);

mVideoDuration = (TextView) findViewById(R.id.video_duration);

mSeekBar = (SeekBar) findViewById(R.id.video_progress);

mVideoPorgressContainer = findViewById(R.id.video_progress_container);

mVideoVr = findViewById(R.id.video_vr);

mVideoView.setInfoButtonEnabled(false);//设置左侧信息原圈不可见

mVideoView.setFullscreenButtonEnabled(false);//设置全屏按钮不可见

mVideoView.setStereoModeButtonEnabled(false);//设置立体眼镜模式按钮不可见

}

private void initData() {

Uri uri;

if (“”.equals(mUrl)) {

uri = Uri.parse(“http://resource.vr-store.cn/appfile/6cc160ba38394af0a251d4275ea66c29.mp4”);//坝上的云

} else {

uri = Uri.parse(mUrl);

}

VrVideoView.Options option = new VrVideoView.Options();

try {

mVideoView.loadVideo(uri, option);

} catch (IOException e) {

e.printStackTrace();

}

}

private void initListener() {

mPlayView.setOnClickListener(this);

mVideoVr.setOnClickListener(this);

mSeekBar.setOnSeekBarChangeListener(new SeekBarListener());

mVideoView.setEventListener(new VrVideoEventListener() {

@Override

public void onClick() {

//处理控制面板的显示和隐藏

int visibility = mVideoPorgressContainer.getVisibility();

mVideoPorgressContainer.setVisibility(visibility == View.VISIBLE ? View.GONE : View.VISIBLE);

}

/**

  • Make the video mPlayView in a loop. This method could also be used to move to the next video in

  • a playlist.

*/

@Override

public void onCompletion() {

//播放完成后的操作

//mVideoView.seekTo(0);//循环播放效果

}

@Override

public void onNewFrame() {

updateVideoProgress();

}

@Override

public void onLoadSuccess() {

long duration = mVideoView.getDuration();//视频总时长,毫秒

mTotalDuration = RegularExpress.parseDuration(duration);

mSeekBar.setMax((int) duration);

}

@Override

public void onLoadError(String errorMessage) {

super.onLoadError(errorMessage);

Toast.makeText(PlayerActivity.this, “加载视频失败”, Toast.LENGTH_SHORT).show();

}

@Override

public void onDisplayModeChanged(int newDisplayMode) {

super.onDisplayModeChanged(newDisplayMode);

}

});

}

/**

  • 更新播放进度

*/

private void updateVideoProgress() {

long currentPosition = mVideoView.getCurrentPosition();

String currentPos = RegularExpress.parseDuration(currentPosition);

mSeekBar.setProgress((int) (currentPosition));//更新播放进度

StringBuilder sb = new StringBuilder();

sb.append(currentPos);

sb.append(" / ");

sb.append(mTotalDuration);

mVideoDuration.setText(sb);

}

@Override

public void onClick(View view) {

switch (view.getId()) {

case R.id.play:

performClickPlay();

break;

case R.id.video_vr:

performClickVideoVr();

break;

default:

break;

}

}

private void performClickVideoVr() {

mVideoView.setDisplayMode(3);//enterStereoMode,眼镜模式

}

/**

  • 播放暂停切换

*/

private void performClickPlay() {

if (isPlaying) {

mVideoView.pauseVideo();

mPlayView.setImageResource(R.mipmap.play);

isPlaying = false;

} else {

mVideoView.playVideo();

mPlayView.setImageResource(R.mipmap.stop);

isPlaying = true;

}

}

@Override

protected void onPause() {

super.onPause();

// Prevent the view from rendering continuously when in the background.

mVideoView.pauseRendering();

// If the video is playing when onPause() is called, the default behavior will be to pause

// the video and keep it paused when onResume() is called.

isPlaying = false;

}

@Override

protected void onResume() {

super.onResume();

// Resume the 3D rendering.

mVideoView.resumeRendering();

}

@Override

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以戳这里获取

ed.

isPlaying = false;

}

@Override

protected void onResume() {

super.onResume();

// Resume the 3D rendering.

mVideoView.resumeRendering();

}

@Override

[外链图片转存中…(img-j4klxfN7-1715515719587)]
[外链图片转存中…(img-azpnglfO-1715515719587)]
[外链图片转存中…(img-XAns7EYc-1715515719587)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以戳这里获取

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/820738
推荐阅读
相关标签
  

闽ICP备14008679号