VideoView中的视频不会显示

时间:2011-03-19 21:13:19

标签: java android relativelayout android-videoview

我有一个应用程序,在我的布局中(请参阅下面的xml)有VideoViewTextView(我的问题here中的相同应用程序,但布局有一些变化)。显示TextView并滚动正常,但是当我尝试启动它时,现在不显示视频。我做错了什么?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
<VideoView
    android:id="@+id/videoview"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/textview"
/>
<TextView 
    android:id="@+id/textview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_alignParentBottom="true"
    android:maxLines="30" 
    android:text="My test App"
/>
</RelativeLayout>

编辑:添加一些Java代码

我使用它的代码非常简单:

setContentView(R.layout.auto);

_mTextView = (TextView)findViewById(R.id.textview);
_mTextView.setLines(30);
_mTextView.setMovementMethod(new ScrollingMovementMethod());

_mVideoView = (VideoView)findViewById(R.id.videoview);

要启动视频我使用的是TCP服务器和反射,如果删除TextView

,它就可以正常工作

2 个答案:

答案 0 :(得分:0)

为什么不使用surfaceview,你使用的是媒体播放器吗?

private void iniElements() {
    mPreview = (SurfaceView) findViewById(R.id.screen_tutorial_video_surface);
    holder = mPreview.getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder.setFixedSize(getWindow().getWindowManager().getDefaultDisplay().getWidth(), getWindow().getWindowManager().getDefaultDisplay().getHeight());
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setDisplay(holder);
}

private void iniPlayer() {
    try {
        mMediaPlayer.setDataSource(videoPath); 
        mMediaPlayer.prepare();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}

答案 1 :(得分:0)

我能够找到问题的解决方案,返回solution I got here(感谢Sunil)并稍微修改一下(在我的问题中也提到过):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
<VideoView
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/videoview"
    android:layout_above="@+id/ScrollView01"
/>
<ScrollView   
    android:id="@+id/ScrollView01"  
    android:layout_height="350px"   
    android:layout_width="fill_parent"
    android:layout_gravity="bottom"
    android:layout_alignParentBottom="true"
    >
<TextView 
    android:layout_width="wrap_content" 
    android:id="@+id/textview" 
    android:layout_height="wrap_content" 
    android:text="Wellcome"
/>
</ScrollView>
</RelativeLayout>

更改位于ScrollView中 - android:layout_height="350px"而非android:layout_height="wrap content",它将其置于屏幕的下半部分,但具有特定大小且不超过该值。 虽然它不是最干净的方式,但确实能满足我的需要。我希望有人会发现它很有用。