2011-03-19 92 views
0

我有一個應用程序,並在我的佈局(見下面的XML)有VideoViewTextView(從我的問題here相同的應用程序,但在佈局的一些變化)。該TextView顯示和卷軸很好,但現在當我試圖啓動它時,視頻不顯示。我究竟做錯了什麼?視頻在VideoView

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

+0

只顯示一個xml佈局文件不會幫助任何人回答你的問題 - 你需要顯示你正在使用的代碼。 – Squonk 2011-03-19 21:16:55

+0

@MisterSquonk謝謝。添加。我希望這有幫助。 – MByD 2011-03-19 21:22:23

回答

0

嗯,我可以通過返回solution I got here(感謝蘇尼爾),以找到一個解決我的問題,並稍作修改(我的問題也提到了):

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

的變化在滾動查看 - android:layout_height="350px"而不是android:layout_height="wrap content"它把它放在屏幕的下半部分,但具有特定的大小,不超過。儘管它不是最乾淨的方式,它確實滿足我需要的東西。我希望有人會覺得它有用。

0

爲什麼你不使用surfaceview,並且你正在使用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); 
} 
+0

我使用'VideoView'作爲更大程序的一部分。由於'VideoView'實際上是'MediaPlayer'和Surface的封裝,所以我沒有理由單獨管理它。我不認爲這是相關的,但一些佈局配置。 – MByD 2011-03-19 21:36:02