0

我有一个应用程序,在我的布局中(参见下面的 xml)有VideoViewTextView(与我的问题相同的应用程序但布局有一些变化)。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

4

2 回答 2

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);
}
于 2011-03-19T21:29:22.573 回答
0

好吧,我能够通过返回我在这里得到的解决方案(感谢 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>

The change is in the ScrollView - android:layout_height="350px" instead of android:layout_height="wrap content" which put it in the lower part of the screen, but with a specific size and no more than that. Though it is not the cleanest way possible, it does fulfill exactly what I need. I hope someone will find it useful.

于 2011-03-29T19:53:41.403 回答