【问题标题】:Video in VideoView is not displayedVideoView中的视频不显示
【发布时间】:2011-03-19 21:13:18
【问题描述】:

我有一个应用程序,在我的布局中(参见下面的 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 就可以正常工作

【问题讨论】:

  • 只显示一个 xml 布局文件并不能帮助任何人回答您的问题 - 您需要显示您正在使用的代码。
  • @MisterSquonk 谢谢。添加。我希望它会有所帮助。

标签: java android android-relativelayout android-videoview


【解决方案1】:

你为什么不使用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);
}

【讨论】:

  • 我将VideoView 用作更大程序的一部分。由于VideoView 实际上是MediaPlayer 和表面的封装,我认为没有理由单独管理它。我认为这与此无关,但与某些布局配置有关。
【解决方案2】:

嗯,我能够通过返回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" 将其放在屏幕的下部,但具有特定的大小,仅此而已。 虽然这不是最干净的方式,但它确实满足了我的需要。我希望有人会觉得它有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多