Java VR Android应用程序没有响应
我正在构建一个简单的360视频查看器,但它不断崩溃 下面是“选择代码”页面,当用户单击“查看视频”时,360视频将打开Java VR Android应用程序没有响应,java,android,virtual-reality,Java,Android,Virtual Reality,我正在构建一个简单的360视频查看器,但它不断崩溃 下面是“选择代码”页面,当用户单击“查看视频”时,360视频将打开 package com.example.jal.jp; import android.content.Intent; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.wid
package com.example.jal.jp;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
public class Choices extends AppCompatActivity {
public Button first_button;
//public Button second_button;
public void init(){
first_button = (Button)findViewById(R.id.video);
// second_button = (Button)findViewById(R.id.video);
first_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent view = new Intent(Choices.this,VR_Video.class);
startActivity(view);
}
});
/** second_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent view2 = new Intent(Choices.this,VR_Video.class);
startActivity(view2);
}
});*/
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choices);
init();
}
}
下面是视频查看器文件的代码
package com.example.jal.jp;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import com.google.vr.sdk.widgets.video.VrVideoEventListener;
import com.google.vr.sdk.widgets.video.VrVideoView;
import java.io.IOException;
public abstract class VR_Video extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
private static final String STATE_PROGRESS = "state_progress";
private static final String STATE_DURATION = "state_duration";
private VrVideoView mVrVideoView;
private SeekBar mSeekBar;
private Button mVolumeButton;
private boolean mIsPaused;
private boolean mIsMuted;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vr__video);
initViews();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putLong(STATE_PROGRESS, mVrVideoView.getCurrentPosition());
outState.putLong(STATE_DURATION, mVrVideoView.getDuration());
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
long progress = savedInstanceState.getLong(STATE_PROGRESS);
mVrVideoView.seekTo(progress);
mSeekBar.setMax((int) savedInstanceState.getLong(STATE_DURATION));
mSeekBar.setProgress((int) progress);
}
public void onPlayPausePressed() {
}
public void onVolumeToggleClicked() {
mIsMuted = !mIsMuted;
mVrVideoView.setVolume(mIsMuted ? 0.0f : 1.0f);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if( fromUser ) {
mVrVideoView.seekTo(progress);
}
}
private void initViews() {
mVrVideoView = (VrVideoView) findViewById(R.id.video_view);
mSeekBar = (SeekBar) findViewById(R.id.seek_bar);
mVolumeButton = (Button) findViewById(R.id.btn_volume);
mVrVideoView.setEventListener(new ActivityEventListener());
//try { VrVideoView.Options options = new VrVideoView.Options(); options.inputType = VrVideoView.Options.TYPE_MONO;
// mVrVideoView.loadVideoFromAsset("sea.mp4", options); } catch( IOException e ) { //Handle exception }
mSeekBar.setOnSeekBarChangeListener(this);
mVolumeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onVolumeToggleClicked();
}
});
}
class VideoLoaderTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... voids) {
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
// VrVideoView.Options options = new VrVideoView.Options();
//options.inputType = VrVideoView.Options.TYPE_MONO;
VrVideoView.Options options = new VrVideoView.Options(); options.inputType = VrVideoView.Options.TYPE_MONO;
mVrVideoView.loadVideoFromAsset("sea.mp4", options);
} catch(IOException e) {
//Handle exception
}
//your code here
}
});
return true;
}
}
public void playPause() {
if( mIsPaused ) {
mVrVideoView.playVideo();
} else {
mVrVideoView.pauseVideo();
}
mIsPaused = !mIsPaused;
}
@Override
protected void onPause() {
super.onPause();
mVrVideoView.pauseRendering();
mIsPaused = true;
}
@Override
protected void onResume() {
super.onResume();
mVrVideoView.resumeRendering();
mIsPaused = false;
}
@Override
protected void onDestroy() {
mVrVideoView.shutdown();
super.onDestroy();
}
private class ActivityEventListener extends VrVideoEventListener {
@Override
public void onLoadSuccess() {
super.onLoadSuccess();
mSeekBar.setMax((int) mVrVideoView.getDuration());
mIsPaused = false;
}
@Override
public void onLoadError(String errorMessage) {
super.onLoadError(errorMessage);
}
@Override
public void onClick() {
super.onClick();
playPause();
}
@Override
public void onNewFrame() {
super.onNewFrame();
mSeekBar.setProgress((int) mVrVideoView.getCurrentPosition());
}
@Override
public void onCompletion() {
super.onCompletion();
mVrVideoView.seekTo(0);
}
}
}
package com.example.jal.jp;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.support.design.widget.FloatingActionButton;
导入android.support.design.widget.Snackbar;
导入android.support.v7.app.AppActivity;
导入android.support.v7.widget.Toolbar;
导入android.view.view;
导入android.widget.Button;
导入android.widget.SeekBar;
导入com.google.vr.sdk.widgets.video.VrVideoEventListener;
导入com.google.vr.sdk.widgets.video.VrVideoView;
导入java.io.IOException;
公共抽象类VR_Video扩展AppCompatActivity实现SeekBar.onseekbarchaneListener{
私有静态最终字符串STATE\u PROGRESS=“STATE\u PROGRESS”;
私有静态最终字符串STATE\u DURATION=“STATE\u DURATION”;
私有VrVideoView mVrVideoView;
私人SeekBar mSeekBar;
私有按钮mVolumeButton;
私人布尔错误假设;
私用布尔误用;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u vr\u视频);
initViews();
}
@凌驾
SaveInstanceState上受保护的无效(束超出状态){
putLong(STATE_PROGRESS,mVrVideoView.getCurrentPosition());
putLong(STATE_DURATION,mVrVideoView.getDuration());
super.onSaveInstanceState(超出状态);
}
@凌驾
RestoreInstanceState上的受保护无效(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
long progress=savedInstanceState.getLong(STATE_progress);
mVrVideoView.seekTo(进度);
mSeekBar.setMax((int)savedInstanceState.getLong(STATE_DURATION));
mSeekBar.setProgress((int)progress);
}
public void onPlayPausePressed(){
}
公共无效onVolumeToggleClicked(){
静音错误=!静音错误;
mVrVideoView.setVolume(静音错误?0.0f:1.0f);
}
@凌驾
public void onProgressChanged(SeekBar-SeekBar、int-progress、boolean-fromUser){
如果(来自用户){
mVrVideoView.seekTo(进度);
}
}
私有void initViews(){
mVrVideoView=(VrVideoView)findviewbyd(R.id.video\u视图);
mSeekBar=(SeekBar)findViewById(R.id.seek\u bar);
mVolumeButton=(按钮)findviewbyd(R.id.btn\u卷);
mVrVideoView.setEventListener(新的ActivityEventListener());
//尝试{VrVideoView.Options Options=new VrVideoView.Options();Options.inputType=VrVideoView.Options.TYPE_MONO;
//mVrVideoView.loadVideoFromAsset(“sea.mp4”,选项)}捕获(IOException e){//句柄异常}
mSeekBar.setonseekbarchaneglistener(此);
mVolumeButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
onVolumeToggleClicked();
}
});
}
类VideoLoaderTask扩展异步任务{
@凌驾
受保护的布尔doInBackground(Void…voids){
runOnUiThread(新的Runnable(){
@凌驾
公开募捐{
试一试{
//VrVideoView.Options=new VrVideoView.Options();
//options.inputType=VrVideoView.options.TYPE\u MONO;
VrVideoView.Options Options=new VrVideoView.Options();Options.inputType=VrVideoView.Options.TYPE\u MONO;
mVrVideoView.loadVideoFromAsset(“sea.mp4”,选项);
}捕获(IOE异常){
//处理异常
}
//你的代码在这里
}
});
返回true;
}
}
公共空间暂停播放(){
如果(错误假设){
mVrVideoView.playVideo();
}否则{
mVrVideoView.pauseVideo();
}
误发=!误发;
}
@凌驾
受保护的void onPause(){
super.onPause();
mVrVideoView.pauseRendering();
假假=真;
}
@凌驾
受保护的void onResume(){
super.onResume();
mVrVideoView.resumeRendering();
误发=假;
}
@凌驾
受保护的空onDestroy(){
mVrVideoView.shutdown();
super.ondestory();
}
私有类ActivityEventListener扩展了VrVideoEventListener{
@凌驾
public void onLoadSuccess(){
super.onLoadSuccess();
mSeekBar.setMax((int)mVrVideoView.getDuration());
误发=假;
}
@凌驾
public void onLoadError(字符串错误消息){
super.onload错误(errorMessage);
}
@凌驾
公共void onClick(){
super.onClick();
播放暂停();
}
@凌驾
public void onNewFrame(){
super.onNewFrame();
mSeekBar.setProgress((int)mVrVideoView.getCurrentPosition());
}
@凌驾
完成时的公共无效(){
super.onCompletion();
mVrVideoView.seekTo(0);
}
}
}
内容选择代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.jal.jp.Choices"
tools:showIn="@layout/activity_choices">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play VR Video"
android:id="@+id/video"
android:layout_marginTop="102dp"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/survey"
android:layout_alignStart="@+id/survey"
android:background="#403e97"
android:layout_alignRight="@+id/survey"
android:layout_alignEnd="@+id/survey"
android:textColor="#be3e3e" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take the Survey"
android:id="@+id/survey"
android:layout_marginTop="105dp"
android:layout_below="@+id/video"
android:layout_centerHorizontal="true"
android:allowUndo="true"
android:background="#2845a6"
android:textColor="#8f2626" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="360 View"
android:id="@+id/view"
android:layout_marginTop="89dp"
android:layout_below="@+id/survey"
android:layout_alignLeft="@+id/video"
android:layout_alignStart="@+id/video"
android:background="#223e80"
android:layout_alignRight="@+id/video"
android:layout_alignEnd="@+id/video"
android:textColor="#bf1b1b" />
</RelativeLayout>
活动\u vr\u video.xml的代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.vr.sdk.widgets.video.VrVideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="250dp"/>
<SeekBar
android:id="@+id/seek_bar"
android:layout_height="32dp"
android:layout_width="match_parent"
style="?android:attr/progressBarStyleHorizontal"/>
<Button
android:id="@+id/btn_volume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Volume Toggle"/>
</LinearLayout>
事故日志:
06-27 00:03:17.626 1529-1548/? I/ActivityManager: Displayed com.example.jal.jp/.Choices: +387ms
06-27 00:03:17.716 2776-2789/? E/Surface: getSlotFromBufferLocked: unknown buffer: 0xae9f0230
06-27 00:03:18.259 1609-1609/? D/skia: --- SkImageDecoder::Factory returned null
06-27 00:03:22.295 1529-1541/? I/ActivityManager: START u0 {cmp=com.example.jal.jp/.VR_Video} from uid 10058 on display 0
06-27 00:03:22.349 2776-2776/? D/AndroidRuntime: Shutting down VM
06-27 00:03:22.350 2776-2776/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jal.jp, PID: 2776
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.jal.jp/com.example.jal.jp.VR_Video}: java.lang.InstantiationException: java.lang.Class<com.example.jal.jp.VR_Video> cannot be instantiated
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.InstantiationException: java.lang.Class<com.example.jal.jp.VR_Video> cannot be instantiated
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-27 00:03:22.372 1529-1905/? W/ActivityManager: Force finishing activity com.example.jal.jp/.VR_Video
06-27 00:03:22.384 1529-1905/? W/ActivityManager: Force finishing activity com.example.jal.jp/.Choices
06-27 00:03:22.483 1529-2747/? I/OpenGLRenderer: Initialized EGL, version 1.4
06-27 00:03:22.772 1529-2747/? W/EGL_emulation: eglSurfaceAttrib not implemented
06-27 00:03:22.772 1529-2747/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9b1d1ba0, error=EGL_SUCCESS
06-27 00:03:22.886 1529-1543/? W/ActivityManager: Activity pause timeout for ActivityRecord{a0649b u0 com.example.jal.jp/.VR_Video t26 f}
06-27 00:03:24.063 1609-1609/? D/skia: --- SkImageDecoder::Factory returned null
06-27 00:03:32.309 1529-1543/? W/ActivityManager: Launch timeout has expired, giving up wake lock!
06-27 00:03:32.390 1529-1543/? W/ActivityManager: Activity destroy timeout for ActivityRecord{3e989dd u0 com.example.jal.jp/.Choices t26 f}
06-27 00:03:42.336 1529-1543/? W/ActivityManager: Activity destroy timeout for ActivityRecord{a0649b u0 com.example.jal.jp/.VR_Video t26 f}
06-27 00:03:17.6261529-1548/?I/ActivityManager:displated com.example.jal.jp/.Choices:+387ms
06-27 00:03:17.716 2776-2789/? E/Surface:getSlotFromBufferLocked:未知缓冲区:0xae9f0230
06-27 00:03:18.259 1609-1609/? D/skia:---SkImageDecoder::工厂返回null
06-27 00:03:22.295 1529-1541/? I/ActivityManager:在显示上从uid 10058启动u0{cmp=com.example.jal.jp/.VR_Video}
Intent view = new Intent(Choices.this,VR_Video.class);
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}