Double vision problem in 360 player in phones that are not screen 16: 9, using com.google.vrtoolkit.cardboard in Android Studio

0

I comment, I have a player created on Android. It is for videos in 360. The problem arises when I try to play videos on phones such as the Samsung Galaxy s8 and s8 + (Do not probe in others of this type). When placing them in a viewer it looks double. I can not hit the target where I have to modify values to be able to fix this in models of this type with 18: 9 screens. On 16: 9 screens it works perfectly.

I do not know if it makes a lot of sense to show him the encoding because I think he should touch a bit of the SDK catch, but I pass them what I have.

Thank you very much!

VideoPLayerActivity.java

 public class VideoPlayerActivity extends CardboardActivity implements           PFAssetObserver, SeekBar.OnSeekBarChangeListener,
    PFHotspotClickListener, View.OnTouchListener {


PFView _pfview;
PFAsset _pfasset;

boolean _updateThumb = true;
Timer _scrubberMonitorTimer;

ViewGroup _frameContainer;
SeekBar _scrubber;

ImageView _playButton;
ImageView _pauseButton;
ImageView _cardboardButton;
ImageView _noCardboardButton;

ImageView _lPlayButtonCardboard;
ImageView _rPlayButtonCardboard;

ViewGroup barraTop;
ViewGroup barraBottom;

TextView contadorInicial;
TextView contadorFinal;

RelativeLayout hide_show;

String URL_VIDEO;
String day;

boolean isVideo = true;
boolean isFocus = true;
boolean isShare = true;
String day1;

public String check = "seen";
public String email;
public int gender;
private User user;
String urlVideo;
private String dateFirst;
private int porcentajeAvance;
private String genero;

ProgressBar progress_loader;
private SharedPreferencesManager spMgr;
private String STORAGE_PATH = Environment.getExternalStorageDirectory() + File.separator + "MindCotine";
/**
 * Click listener for the play/pause button
 */
private View.OnClickListener playListener = new View.OnClickListener() {
    public void onClick(View v) {

        if (_pfasset.getStatus() == PFAssetStatus.PLAYING) {
            _pfasset.pause();
            _updateThumb = false;
        } else {
            if (_pfview != null) {
                _pfview.injectImage(null);
            }
            _updateThumb = true;
            _pfasset.play();
        }
    }
};
private View.OnClickListener pauseListener = new View.OnClickListener() {
    public void onClick(View view) {
        if (_pfasset.getStatus() == PFAssetStatus.PLAYING) {
            _pfasset.pause();
            _updateThumb = false;
        } else {
            _updateThumb = true;
            _pfasset.play();
        }
    }
};
/**
 * Click listener for the cardboard/nocardboard button
 */

private View.OnClickListener cardboardListener = new View.OnClickListener() {
    public void onClick(View view) {
        _noCardboardButton.setVisibility(View.VISIBLE);
        _cardboardButton.setVisibility(View.GONE);
        _pfview.setNavigationMode(PFNavigationMode.MOTION);
        _pfview.setMode(2, 360);
    }
};
private View.OnClickListener noCardboardListener = new View.OnClickListener() {
    public void onClick(View view) {
        _noCardboardButton.setVisibility(View.GONE);
        _cardboardButton.setVisibility(View.VISIBLE);
        _pfview.setNavigationMode(PFNavigationMode.TOUCH);
        _pfview.setMode(0, 360);
    }
};

/**
 * Creation and initalization of the Activitiy.
 * Initializes variables, listeners, and starts request of a movie list.
 *
 * @param savedInstanceState a saved instance of the Bundle
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_video_player);

    Bundle extras = getIntent().getExtras();


    URL_VIDEO = extras.getString("URL_VIDEO");
    isVideo = extras.getBoolean("VIDEO_OR_AUDIO", true);
    day = extras.getString("is_day");
    day1 = extras.getString("DIA");

    Log.d("SimplePlayer URL", " " + URL_VIDEO);
    spMgr = new SharedPreferencesManager(this);

    _frameContainer = (ViewGroup) findViewById(R.id.framecontainer);
    _frameContainer.setBackgroundColor(0xFF000000);

    contadorInicial = (TextView) findViewById(R.id.contadorInicial);
    contadorFinal = (TextView) findViewById(R.id.contadorFinal);
    _scrubber = (SeekBar) findViewById(R.id.scrubber);
    _playButton = (ImageView) findViewById(R.id.playButton);
    _pauseButton = (ImageView) findViewById(R.id.pauseButton);
    _cardboardButton = (ImageView) findViewById(R.id.cardboardButton);
    _noCardboardButton = (ImageView) findViewById(R.id.noCardboardButton);
    _lPlayButtonCardboard = (ImageView) findViewById(R.id.lPlayButtonCardboard);
    _rPlayButtonCardboard = (ImageView) findViewById(R.id.rPlayButtonCardboard);
    progress_loader = (ProgressBar) findViewById(R.id.progress_loader);

    _cardboardButton.setOnClickListener(cardboardListener);
    _noCardboardButton.setOnClickListener(noCardboardListener);
    _playButton.setOnClickListener(playListener);
    _pauseButton.setOnClickListener(pauseListener);
    _scrubber.setOnSeekBarChangeListener(this);
    _scrubber.setEnabled(false);

    barraTop = (ViewGroup) findViewById(R.id.barraTop);
    barraBottom = (ViewGroup) findViewById(R.id.barraBottom);
    hide_show = (RelativeLayout) findViewById(R.id.hide_show);

    showControls(true);
    hide_show.setOnTouchListener(this);
    _cardboardButton.setVisibility(View.INVISIBLE);

    final UserSesion sesion = new UserSesion(this);
    user = sesion.getSession();

}

@Override
public void onStart() {
    super.onStart();
    Log.d("EOA", "onStart");
    if (_pfasset == null)
        loadVideo(URL_VIDEO);
    _pfasset.play();
    _updateThumb = true;

}

public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (_pfview != null)
        _pfview.handleOrientationChange();
}

/**
 * Show/Hide the playback controls
 *
 * @param bShow Show or hide the controls. Pass either true or false.
 */
public void showControls(boolean bShow) {
    int visibility = View.GONE;

    if (bShow)
        visibility = View.VISIBLE;

    _playButton.setVisibility(visibility);
    _noCardboardButton.setVisibility(visibility);
    _scrubber.setVisibility(visibility);
}

/**
 * Start the video with a local file path
 *
 * @param filename The file path on device storage
 */

public void loadVideo(String filename) {

    _pfview = PFObjectFactory.view(this);
    _pfasset = PFObjectFactory.assetFromUri(this, Uri.parse(filename), this);
    _pfview.displayAsset(_pfasset);
    _pfview.setViewRotationOffsetX(1);
    //_pfview.setBlindSpotPosition(1);
    //_pfview.setBlindSpotScale(1.5f);
    _pfview.setNavigationMode(PFNavigationMode.MOTION);
    _pfview.setMode(2, 360);
    _frameContainer.addView(_pfview.getView(), 0);
}

/**
 * Status callback from the PFAsset instance.
 * Based on the status this function selects the appropriate action.
 *
 * @param asset  The asset who is calling the function
 * @param status The current status of the asset.
 */
public void onStatusMessage(final PFAsset asset, PFAssetStatus status) {

    Log.d("SimplePlayer status", "" + status);
    switch (status) {
        case LOADED:
            Log.d("SimplePlayer", "Loaded");
            showLoading();
            break;
        case DOWNLOADING:
            Log.d("SimplePlayer", "Downloading 360� movie: " + _pfasset.getDownloadProgress() + " percent complete");
            break;
        case DOWNLOADED:
            Log.d("SimplePlayer", "Downloaded to " + asset.getUrl());
            break;
        case DOWNLOADCANCELLED:
            Log.d("SimplePlayer", "Download cancelled");
            break;
        case PLAYING:
            try {
              //  Toast.makeText(this, "" + URL_VIDEO, Toast.LENGTH_LONG).show();
                Log.d("SimplePlayer", "Playing");
                showViewForAudio();
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                _scrubber.setEnabled(true);
                //_playButton.setText("Pause");
                _pauseButton.setVisibility(View.VISIBLE);
                _playButton.setVisibility(View.GONE);
//                _lPlayButtonCardboard.setVisibility(View.GONE);
//                _rPlayButtonCardboard.setVisibility(View.GONE);
                _scrubberMonitorTimer = new Timer();
                _scrubber.setMax((int) asset.getDuration());
                _scrubber.setProgress((int) asset.getPlaybackTime());
                Log.i("Chelix", "Duracion del video: " + getDurationString(Math.round(asset.getDuration())));
//                Log.i("Chelix", "Playbacktime: " + getDurationString(Math.round(asset.getPlaybackTime())));
                TimerTask task = new TimerTask() {
                    public void run() {
                        if (_updateThumb) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    if (_updateThumb) {
                                        Log.i("Chelix", "Playbacktime: " + getDurationString(Math.round(asset.getPlaybackTime())));
                                        contadorInicial.setText(getDurationString(Math.round(asset.getPlaybackTime())));
                                        contadorFinal.setText(getDurationString(Math.round(asset.getDuration())));
                                        //contadorFinal.setText(Integer.parseInt(getDurationString(Math.round(asset.getDuration()))) - Integer.parseInt(getDurationString(Math.round(asset.getPlaybackTime()))) );
                                        _scrubber.setProgress((int) asset.getPlaybackTime());

                                    }
                                }
                            });
                        }
                    }
                };
                _scrubberMonitorTimer.schedule(task, 0, 33);

                // Checking Whether video is playing and stopping in background thread
                if (isShare) {
                    if (!isFocus) {
                        _pfasset.stop();
                        _updateThumb = false;
                        Log.d("Video Paused", "As Activity Is Not In View");
                    }
                }
                hideLoading();
            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
        case PAUSED:
            Log.d("SimplePlayer", "Paused");
            //_playButton.setText("Play");
            _pauseButton.setVisibility(View.GONE);
            _playButton.setVisibility(View.VISIBLE);
            break;

        case COMPLETE:
            try {
                Log.d("SimplePlayer", "Complete");
                //_playButton.setText("Play");
                _pauseButton.setVisibility(View.GONE);
                _playButton.setVisibility(View.VISIBLE);
                _scrubberMonitorTimer.cancel();
                _scrubberMonitorTimer = null;
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

                Intent intent = new Intent(VideoPlayerActivity.this, DrawerActivity.class);
                startActivity(intent);
                finish();
            } catch (Exception e) {

                e.printStackTrace();
                break;
            }
            break;
        case ERROR:
            Log.d("SimplePlayer", "Error");
            break;
    }
}

/**
 * Called when the Only Audio is played
 */
private void showViewForAudio() {
    if (!isVideo) {
        _lPlayButtonCardboard.setVisibility(View.VISIBLE);
        _rPlayButtonCardboard.setVisibility(View.VISIBLE);
    }
}

/**
 * Called to hide the loading progress
 */
private void hideLoading() {
    progress_loader.setVisibility(View.GONE);
}

/**
 * Called to show the loading progress
 */
private void showLoading() {
    progress_loader.setVisibility(View.VISIBLE);

}

/**
 * Called when the Cardboard trigger is pulled.
 */
@Override
public void onCardboardTrigger() {
    // Always give useri feedback.
    //vibrator.vibrate(50);

    if (_noCardboardButton.getVisibility() == View.VISIBLE) {

        if (_pfasset.getStatus() == PFAssetStatus.PLAYING) {
            _pfasset.pause();
        } else {
            if (_pfview != null) {
                _pfview.injectImage(null);
            }
            _pfasset.play();
        }
    }
}

@Override
protected void onResume() {
    super.onResume();
    Log.d("EOA", "OnResume");
    isFocus = true;
    if (!isShare) {
        if (_pfview != null) {
            _pfview.injectImage(null);
        }
        _updateThumb = true;
        _pfasset.play();
    }
    isShare = true;
}

/**
 * Called when pausing the app.
 * This function pauses the playback of the asset when it is playing.
 */
@Override
public void onPause() {
    super.onPause();
    try {

        Log.d("EOA", "OnPause");
        if (_pfasset != null) {
            if (_pfasset.getStatus() == PFAssetStatus.PLAYING) {
                _pfasset.pause();
                _updateThumb = false;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

/**
 * Called when a previously created loader is being reset, and thus making its data unavailable.
 *
 * @param seekbar  The SeekBar whose progress has changed
 * @param progress The current progress level.
 * @param fromUser True if the progress change was initiated by the useri.
 */
public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) {
    if (fromUser && isFocus) {
        showLoading();
        _pfasset.setPLaybackTime(progress);
    } else {
        hideLoading();
    }
}

/**
 * Notification that the useri has started a touch gesture.
 * In this function we signal the timer not to update the playback thumb while we are adjusting it.
 *
 * @param seekbar The SeekBar in which the touch gesture began
 */
public void onStartTrackingTouch(SeekBar seekbar) {
    _updateThumb = false;
}

/**
 * Notification that the useri has finished a touch gesture.
 * In this function we request the asset to seek until a specific time and signal the timer to resume the update of the playback thumb based on playback.
 *
 * @param seekbar The SeekBar in which the touch gesture began
 */
public void onStopTrackingTouch(SeekBar seekbar) {
    _updateThumb = true;
}

@Override
public void onClick(PFHotspot pfHotspot) {

}

@Override
public void onBackPressed() {
    super.onBackPressed();
    Log.d("EOA", "back press");
    _pfasset.stop();
    _updateThumb = false;
    isFocus = false;

    Intent intent = new Intent(VideoPlayerActivity.this, DrawerActivity.class);
    startActivity(intent);
    finish();
}

public void onClick(View view) {
    switch (view.getId()) {
        case R.id.back:
            Log.d("EOA", "OnPBack Button");
            onBackPressed();
            break;
        case R.id.share:
            if (_pfasset.getStatus() == PFAssetStatus.PLAYING) {
                _pfasset.pause();
            }
            isShare = false;
            String s = getString(R.string.share_subject);
            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.share_subject));
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, getString(R.string.share_text));
            startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_chooser_title)));
            break;
    }
}

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    if (barraBottom.getVisibility() == View.VISIBLE) {
        barraTop.setVisibility(View.GONE);
        barraBottom.setVisibility(View.GONE);
    } else if (barraBottom.getVisibility() == View.GONE) {
        barraTop.setVisibility(View.VISIBLE);
        barraBottom.setVisibility(View.VISIBLE);
    }
    return false;
}

private String getDurationString(int seconds) {
    int hours = seconds / 3600;
    int minutes = (seconds % 3600) / 60;
    seconds = seconds % 60;

    return twoDigitString(minutes) + ":" + twoDigitString(seconds);
}

private String twoDigitString(int number) {
    if (number == 0) {
        return "00";
    }
    if (number / 10 == 0) {
        return "0" + number;
    }
    return String.valueOf(number);
}

}

activity_video_player.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/framecontainer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout
        android:id="@+id/hide_show"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <!-- REPRODUCTOR EN 2D PARA VISUALIZAR CONTENIDO EN 360° -->

    <RelativeLayout
        android:id="@+id/barraTop"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_gravity="top"
        android:background="#AA000000"
        android:visibility="visible">

        <ImageView
            android:id="@+id/back"
            android:layout_width="32dp"
            android:layout_height="64dp"
            android:layout_alignParentLeft="true"
            android:onClick="onClick"
            android:src="@drawable/ic_keyboard_arrow_left_black_24dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="70dp"
            android:layout_marginTop="6dp"
            android:text="@string/video"
            android:textColor="@android:color/white"
            android:textSize="20sp"
            android:textStyle="bold" />

        <ImageView
            android:id="@+id/share"
            android:layout_width="32dp"
            android:layout_height="24dp"
            android:layout_alignParentRight="true"
            android:layout_marginRight="8dp"
            android:layout_marginTop="6dp"
            android:onClick="onClick"
            android:src="@drawable/ic_cast_black_24dp" />

    </RelativeLayou

    <RelativeLayout
        android:id="@+id/barraBottom"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_gravity="bottom"
        android:background="#AA000000"
        android:visibility="visible">


        <ImageView
            android:id="@+id/playButton"
            android:layout_width="32dp"
            android:layout_height="24dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignTop="@+id/scrubber"
            android:onClick="onClick"
            android:src="@drawable/ic_play_arrow_black_24dp" />

        <ImageView
            android:id="@+id/pauseButton"
            android:layout_width="32dp"
            android:layout_height="24dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignTop="@+id/scrubber"
            android:onClick="onClick"
            android:src="@drawable/ic_pause_black_24dp"
            android:visibility="invisible" />


        <TextView
            android:id="@+id/contadorInicial"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignTop="@+id/scrubber"
            android:layout_toRightOf="@+id/playButton"
            android:paddingLeft="45dp"
            android:paddingTop="10dp"
            android:text="0:00"
            android:textColor="@android:color/white"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/contadorFinal"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/scrubber"
            android:layout_toLeftOf="@+id/cardboardButton"
            android:paddingRight="55dp"
            android:paddingTop="10dp"
            android:text="0:00"
            android:textColor="@android:color/white"
            android:textSize="15sp" />

        <SeekBar
            android:id="@+id/scrubber"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_toLeftOf="@+id/contadorFinal"
            android:layout_toRightOf="@+id/contadorInicial"
            android:clickable="false"
            android:indeterminate="false"
            android:paddingLeft="22dp"
            android:paddingRight="22dp"
            android:paddingTop="6dp"
            android:progressTint="@android:color/white"
            android:splitTrack="false"
            android:thumbTint="@android:color/white" />

        <ImageView
            android:id="@+id/cardboardButton"
            android:layout_width="32dp"
            android:layout_height="24dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/scrubber"
            android:layout_marginRight="8dp"
            android:onClick="onClick"
            android:src="@drawable/ic_google_cardboard_24dp"
            android:visibility="visible" />

        <ImageView
            android:id="@+id/noCardboardButton"
            android:layout_width="32dp"
            android:layout_height="24dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/scrubber"
            android:layout_marginRight="8dp"
            android:onClick="onClick"
            android:src="@drawable/ic_visibility_black_24dp"
            android:visibility="invisible" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center">

        <ProgressBar
            android:id="@+id/progress_loader"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="visible" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:weightSum="100">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="50"
            android:gravity="center">

            <ImageView
                android:id="@+id/rPlayButtonCardboard"
                android:layout_width="64dp"
                android:layout_height="64dp"
                android:src="@drawable/play_button_shape"
                android:visibility="gone" />

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_weight="50"
                android:gravity="center">

                <ImageView
                    android:id="@+id/lPlayButtonCardboard"
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:src="@drawable/play_button_shape"
                    android:visibility="gone" />
            </RelativeLayout>
        </RelativeLayout>
    </LinearLayout>

</FrameLayout>

    
asked by FabriC 07.03.2018 в 17:08
source

0 answers