简体   繁体   English

按后退按钮时,我的“视频视图”为空白。 我该如何解决?

[英]my "video view" is blank when pressing the back button. How i can fix it?

So, i have a video view for my background.所以,我有一个视频视图作为我的背景。 There i put image view as button.我把图像视图作为按钮。 when i go to other activity and then go back, my video cannot play.当我 go 到其他活动然后 go 回来时,我的视频无法播放。 just blank.只是空白。 Sorry about my english.对不起我的英语。

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pilih_user);

        VideoView videoview = (VideoView) findViewById(R.id.videoView);
        Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.test);
        videoview.setVideoURI(uri);
        videoview.start();

        ImageView apin = findViewById(R.id.pilihguru);

        apin.setOnClickListener(view ->

        {
            Intent intent = new Intent(PilihUser.this, DaftarPembelajaran.class);
            startActivity(intent);
        });
    }

}

And this my layout.这是我的布局。 I use constraint and then put video view as background.我使用约束,然后将视频视图作为背景。 This my first time to build simple app by java.这是我第一次通过 java 构建简单的应用程序。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:id="@+id/layoutpilihuser"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bghome"
    tools:context=".PilihUser">

    <VideoView
        android:id="@+id/videoView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    <ImageView
        android:id="@+id/pilihanak"
        android:layout_width="200dp"
        android:layout_height="94dp"
        android:layout_marginTop="64dp"
        android:contentDescription="@string/app_name"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.499"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/videoView"
        app:srcCompat="@drawable/pilihuser1" />

    <ImageView
        android:id="@+id/pilihguru"
        android:layout_width="200dp"
        android:layout_height="94dp"
        android:layout_marginTop="28dp"
        android:contentDescription="@string/app_name"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.499"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/pilihanak"
        app:srcCompat="@drawable/pilihuser2" />

</android.support.constraint.ConstraintLayout>

You need to call videoview.start() in onResume:您需要在 onResume 中调用 videoview.start():

@Override
public void onResume(){
    super.onResume();
    videoview.start();

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想通过按一个按钮在Textview上产生波纹效果。 可能吗? 我该怎么做? - I want to make Ripple effect on Textview by pressing a button. Is it possible? How can I do it? 如何通过按后退按钮跳转到片段? - How can I jump to a fragment by pressing the back button? 按后退按钮移动到上一个片段时显示空白屏幕 - Blank screen is displayed when pressing the back button to move to previous fragment 在我的android项目中,有两个类,并且在第一类上有一个按钮,当我单击按钮时,我需要查看下一页。 - In my android project there are two classes and there is a button on first class,i need to view next page when i click on the button. 如何按下按钮来暂停Image View更新? - How can I pause an Image View update by pressing a button? 如何在不按录制按钮的情况下启用自动开始录制视频? - How can I enable auto start recording video without pressing record button? 当我从 main 方法调用我的 JFrame 子类时,我得到一个空白 JFrame。 我该如何解决? - I get a blank JFrame when i call my the JFrame subclass from the main method. How can I fix? 按下返回按钮时如何获取最后使用的片段 - How to get last Fragment used when pressing back button 在主活动中按“后退”按钮时如何退出应用程序? - how to make the appliction exit when pressing back button in the main activity? 按下重置按钮后出现NullPointerException。 (处理)对 - NullPointerException after pressing reset button. (Processing)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM