簡體   English   中英

VR Android應用無響應

[英]VR Android app not responding

在此處輸入圖片說明

我正在構建一個簡單的360 Video Viewer,但是它一直崩潰。

以下是“選擇代碼”頁面,當用戶單擊觀看視頻時,應打開360視頻。

 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);

        }

    }
}

Content_choices的代碼。

<?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>

activity_vr_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}

您的問題在這一行:

Intent view = new Intent(Choices.this,VR_Video.class);

由於嘗試啟動VR_Video活動而收到錯誤,但這是一個抽象類。 刪除您的VR_Video類中的abstract關鍵字,它將起作用。

並實現您的接口方法:

@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM