通常情况下,Android的VideoView是不显示视频,音频播放。我怎样才能获得的视频显示时间的100% [英] Usually, Android VideoView is does not show video, audio is playing. How can I get the video to show 100% of the time

查看:287
本文介绍了通常情况下,Android的VideoView是不显示视频,音频播放。我怎样才能获得的视频显示时间的100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用单为Android。

我已经通过所有的职位我可以找到关于使用VideoView并不能找到答案倒。我已切换到使用SurfaceView用的MediaPlayer,然后再返回,没有运气。

我想之后用户还没有触及一段时间在屏幕的视频开始播放,所以我有一个保存VideoView一个的FrameLayout,我作出这样可见,当我想要的视频显示。

当我开始播放视频,它通常不显示(时间约80%),但音频开始播放。如果你触摸屏幕,视频显示出来。我已经尝试了不同的视频(.MP4和.3 gp的),但因为你触摸屏幕后的视频实际上是显示,我怀疑它是别的东西。

我也同样的结果尝试此一对夫妇的设备,尽管他们是从同一制造商。它们都考比装置(一个7和其他9.7)以及Android 4.0。我瞄准了Android 2.3的API。

这里是我的xml:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>    ......一束控制...<的FrameLayout
        机器人:ID =@ + ID / videoViewBack
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:背景=#FF000000
        机器人:知名度=水涨船高>
    < VideoView机器人:ID =@ + ID / videoView
              机器人:layout_width =FILL_PARENT
              机器人:layout_height =FILL_PARENT
              机器人:layout_gravity =中心
              机器人:知名度=看得见/>
< /&的FrameLayout GT;
< / LinearLayout中>

和我的函数来启动视频看起来是这样的:

 私人无效StartVideo()
    {        RequestedOrientation = ScreenOrientation.SensorLandscape; //力成景观让视频看起来不错        的FrameLayout vidBack = FindViewById<&的FrameLayout GT;(Resource.Id.videoViewBack);
        vidBack.Visibility = ViewStates.Visible;        VideoView VID = FindViewById< VideoView>(Resource.Id.videoView);
        vid.SetOnTouchListener(本);
        vid.SetOnCompletionListener(本);
        vid.SetVideoPath(_attractFile);
        vid.SetMediaController(新的MediaController(本));
        vid.RequestFocus();
        vid.Start();
    }

我也试图放置调用start()在在preparedListener但是这并没有帮助。

我拉出我的头发,并希望有人知道什么愚蠢的事情,我忘了做。

编辑:

在该理论认为,问题涉及的布局传递不是大小的视频正确,我做这似乎已经修正了该问题如下。但我不是100%肯定,为什么,或者如果它只是戳果冻

在在prepared处理我说:

 查看mainScreen = FindViewById<视图>(Resource.Id.MainScreen);
mainScreen.RequestLayout();
mainScreen.PostInvalidateDelayed(1000);
mainScreen.PostInvalidate();

其中mainScreen是我的XML主要的FrameLayout。在做PostInvalidate固定它的大部分时间,加入PostInvalidateDelayed固定它的时间(我认为:))。

100%

思考,为什么这个工程?


解决方案

  @覆盖
公共无效surfaceCreated(最终SurfaceHolder持有人){
    mPlayer.setDisplay(保持器); //指定SurfaceHolder    gameActivity.handler.post(新的Runnable(){
        @覆盖
        公共无效的run(){
            尝试{
                MPLAYER prepare()。
            }赶上(E1 IllegalStateException异常){
            }赶上(IOException异常E1){
            }
        }
    });
}

I am using Mono for Android.

I've poured through all the posts I can find concerning the use of VideoView and can't find an answer. And I have switched to using a SurfaceView with a MediaPlayer and back again with no luck.

I want a video to start playing after the user has not touched the screen for a while, so I have a FrameLayout that holds the VideoView, and I make that visible when I want the video to show up.

When I start the video, it usually doesn't show up (about 80% of the time), but the audio starts playing. If you touch the screen, the video shows up. I've tried different videos (.mp4 and .3gp), but since the video is actually displaying after you touch the screen, I suspect it is something else.

I have tried this on a couple devices with the same result, albeit they are from from the same manufacturer. They are both Coby devices (one 7" and the other 9.7") and are running Android 4.0. I am targeting Android 2.3 API.

here is my xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

    ... A bunch of controls ...

<FrameLayout
        android:id="@+id/videoViewBack"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FF000000"
        android:visibility="gone">
    <VideoView android:id="@+id/videoView"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_gravity="center"
              android:visibility="visible"/>
</FrameLayout>
</LinearLayout>

and my function to start the video looks like this:

        private void StartVideo()
    {

        RequestedOrientation = ScreenOrientation.SensorLandscape; // Force into landscape so the video looks good

        FrameLayout vidBack = FindViewById<FrameLayout>(Resource.Id.videoViewBack);
        vidBack.Visibility = ViewStates.Visible;

        VideoView vid = FindViewById<VideoView>(Resource.Id.videoView);
        vid.SetOnTouchListener(this);
        vid.SetOnCompletionListener(this);
        vid.SetVideoPath(_attractFile);
        vid.SetMediaController(new MediaController(this));
        vid.RequestFocus();
        vid.Start();
    }

I have also tried to place the Start() call in an OnPreparedListener but that didn't help.

I am pulling out my hair, and hopefully somebody knows what dumb thing I am forgetting to do.

EDIT:

On the theory that the problem was related to the video not being sized correctly in the layout pass, I did the following which seems to have corrected the issue. But I'm not 100% sure why, or if it is just poking jello

In the OnPrepared handler I added:

View mainScreen = FindViewById<View>(Resource.Id.MainScreen);
mainScreen.RequestLayout();
mainScreen.PostInvalidateDelayed(1000);
mainScreen.PostInvalidate();

where mainScreen is the main FrameLayout in my xml. Doing the PostInvalidate fixed it most of the time, adding the PostInvalidateDelayed fixed it 100% of the time (I think :) ).

Thoughts as to why this works?

解决方案

    @Override
public void surfaceCreated(final SurfaceHolder holder) {
    mPlayer.setDisplay(holder); // 指定SurfaceHolder

    gameActivity.handler.post(new Runnable() {
        @Override
        public void run() {
            try {
                mPlayer.prepare();
            } catch (IllegalStateException e1) {
            } catch (IOException e1) {
            }
        }
    });
}

这篇关于通常情况下,Android的VideoView是不显示视频,音频播放。我怎样才能获得的视频显示时间的100%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆