VideoView 播放正常,但在交换全屏视图时不可见

发布于 2024-09-24 19:06:31 字数 2747 浏览 5 评论 0原文

我有一些 AsyncTask 将视频流加载到播放器中,因此我想在执行时显示一些加载屏幕。目前我的onCreate代码如下所示:

final View loadingView = getLayoutInflater().inflate(R.layout.video_loading, null);
final View playerView = getLayoutInflater().inflate(R.layout.player, null);
final VideoView videoView = (VideoView) playerView.findViewById(R.id.canvas);

Log.d(TAG, "Running video player for video " + videoId);

new VideoPlayingTask(this, videoView.getHolder()) {

    protected void onPreExecute() {
        setContentView(loadingView);
        super.onPreExecute(); // it creates or re-uses (resetting it before)
                            // MediaPlayer instance inside and sets display using setDisplay to the passed holder
    };

    protected void onPostExecute(FileInputStream dataSource) {

        setContentView(playerView);
        videoView.requestFocus();
        super.onPostExecute(dataSource); // it sets data source, 
                                        // prepares player and starts it
    };

 }.execute(videoId);

loadingView正确显示,然后将内容更改为playerView时,屏幕变黑,但声音正常播放背景。

我在日志中从 MediaPlayer 收到这两个警告:

info/warning (1, 35)
info/warning (1, 44)

我尝试使用 ViewSwither 并在 onPostExecute 内调用 showNextView,但行为是类似,更改为 videoView 时黑屏。

我已经尝试过将两个内部布局放置在当前内部并手动切换其可见性的方式,这对我也没有帮助。

当我在此活动中仅使用单个 VideoView 时,它可以完美运行并显示图像和声音。

video_loading.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"               
              android:gravity="center">
    <ProgressBar android:layout_width="@dimen/small_progress_side"
                 android:layout_height="@dimen/small_progress_side" />
    <TextView android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
              android:text="@string/caching_video" />
</LinearLayout>

player.xml

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

这个问题似乎有点相似,但是将 loadingView 可见性切换为 INVISIBLE 在我的情况下不起作用。

I have some AsyncTask that loads a video stream into the player, so I want to show some Loading screen while it performs. Currently my onCreate code looks like this:

final View loadingView = getLayoutInflater().inflate(R.layout.video_loading, null);
final View playerView = getLayoutInflater().inflate(R.layout.player, null);
final VideoView videoView = (VideoView) playerView.findViewById(R.id.canvas);

Log.d(TAG, "Running video player for video " + videoId);

new VideoPlayingTask(this, videoView.getHolder()) {

    protected void onPreExecute() {
        setContentView(loadingView);
        super.onPreExecute(); // it creates or re-uses (resetting it before)
                            // MediaPlayer instance inside and sets display using setDisplay to the passed holder
    };

    protected void onPostExecute(FileInputStream dataSource) {

        setContentView(playerView);
        videoView.requestFocus();
        super.onPostExecute(dataSource); // it sets data source, 
                                        // prepares player and starts it
    };

 }.execute(videoId);

loadingView is displayed properly, then when changing content to playerView, screen goes black, but sound plays properly in background.

I get these two warnings from MediaPlayer in the logs:

info/warning (1, 35)
info/warning (1, 44)

I've tried to use ViewSwither and to call showNextView inside onPostExecute, but the behavior was similar, black screen when changing to videoView.

I've tried the way with two inner layouts laying inside current and switch their visibility manually, and this also not helped to me.

When I use just single VideoView in this activity, it works perfectly and shows both image and sound.

video_loading.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"               
              android:gravity="center">
    <ProgressBar android:layout_width="@dimen/small_progress_side"
                 android:layout_height="@dimen/small_progress_side" />
    <TextView android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
              android:text="@string/caching_video" />
</LinearLayout>

player.xml:

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

this question seems a little bit similar, but switching loadingView visibility to INVISIBLE does not work in my case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唔猫 2024-10-01 19:06:31

我刚刚使用了 ProgressDialog.show() 而不是翻转视图,它要简单得多,并且 VideoView 可以正确处理它。

I've just used ProgressDialog.show() instead of flipping views, it is a lot simpler and VideoView handles it right.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文