[英]Android VideoView not playing Portrait Orientation
平台:使用Android SDK 16在Eclipse中開發。
問題:我有一個VideoView元素應該以480x800(PORTRAIT ORIENTATION)填滿整個屏幕,它可以很好地播放,但不會定向到肖像。 它堅持橫向模式,縱橫比傾斜以適應這種方式。
我曾經嘗試過什么:
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="480dp"
android:layout_height="800dp"
android:background="#000000"
android:orientation="vertical" >
<VideoView
android:id="@+id/opening_video"
android:layout_width="480dp"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_height="800dp"
android:orientation="vertical" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/transparent_button"
android:contentDescription="@string/back_button_desc"
android:background="@android:color/transparent" />
</RelativeLayout>
編碼:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_start_screen);
VideoView videoView = (VideoView) findViewById(R.id.opening_video);
Uri pathToVideo = Uri.parse("android.resource://com.example.consumerengage/" + R.raw.opening_tablet);
videoView.setVideoURI(pathToVideo);
videoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
videoView.requestFocus();
videoView.start();
// boolean isPlaying = videoView.isPlaying() ;
// videoView.stopPlayback();
// videoView.clearFocus();
addListenerOnButton();
}
問題:我沒有嘗試過任何成功的事情。 如何讓我的480x800視頻以縱向方式播放?
你確定你的視頻是480x800而不是800x480嗎? 800x480是標准分辨率,如果您使用手機以縱向錄制視頻,則輸出仍為800x480,要正常播放,視頻應旋轉90度。 您所描述的是如果您嘗試在480x800 videoView中播放800x480視頻會發生什么。 如果是這種情況,您可以使用視頻編輯軟件(如Windows Live Moviemaker或iMovie)旋轉它(如果您使用的是Mac)。
您正在使用dp
,您應該使用px
:
<VideoView
android:id="@+id/opening_video"
android:layout_width="480px"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_height="800px"
android:orientation="vertical" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/transparent_button"
android:contentDescription="@string/back_button_desc"
android:background="@android:color/transparent" />
或者,或者(更好) - 只需使用match_parent
(或fill_parent
):
<VideoView
android:id="@+id/opening_video"
android:layout_width="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_height="match_parent"
android:orientation="vertical" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/transparent_button"
android:contentDescription="@string/back_button_desc"
android:background="@android:color/transparent" />
嘗試這個:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<VideoView
android:id="@+id/opening_video"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/transparent_button"
android:contentDescription="@string/back_button_desc"
android:background="@android:color/transparent" />
</RelativeLayout>
希望這可以幫助。 並檢查您的清單文件。
這是我最終做的事情:
問題是操作系統版本。 如果它是ICS(4.0)及以上,它會播放視頻,所以一旦檢測到14或更高的android.os.Build.VERSION.SDK_INT,我加載其側面構建的視頻,以便它播放正確的路。
這是一個非常愚蠢的解決方法,我從來沒有真正得到我的問題的答案。 視頻不應該那樣播放。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.