开发者

Video in VideoView is not displayed

I have an application and in my layout (see xml below)there are VideoView and TextView (same application from my question here, but with a few changes in layout).The TextView is displayed and scrolls fine, but now the video is not displayed when I tried to start it. What am I doing wrong?

<?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>

EDIT: adding some of Java code

My code using it is pretty simple:

setContentView(R.layout.auto);

_mTextView = (TextView)findViewById(R.id.textview);
_mTextView.setLines(30);
_mTextView.setM开发者_高级运维ovementMethod(new ScrollingMovementMethod());

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

To start the video I use a TCP server and reflection, which work just fine if I remove the TextView


Why don't you use a surfaceview, and are you using mediaplayer?

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);
}


Well I was able to find a solution to my problem by returning to the solution I got here (thanks Sunil) and modify it a bit (also mentioned in my question):

<?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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜