簡體   English   中英

VideoView以縱向模式播放,但不以橫向模式播放

[英]VideoView plays in portrait mode but not in landscape mode

我創建了兩種布局,一種是普通布局,另一種是橫向布局。 以下是兩個方向的VideoView xml。 視頻是從URL流式傳輸的。 該視頻在縱向模式下可以完美播放,但是當將方向更改為橫向模式時,則不會播放視頻,而是繼續向我顯示ProgressDialog 下面的代碼可能有助於理解我的問題。

常規布局:

<VideoView
            android:id="@+id/vv_item_video"
            android:layout_width="match_parent"
            android:layout_height="250dp" />

景觀布局:

<VideoView
            android:id="@+id/vv_item_video"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

用於執行VideoView Java代碼:

getWindow().setFormat(PixelFormat.TRANSLUCENT);
vvItemVideo.setVideoURI(Uri.parse(getResUrl()));
vvItemVideo.requestFocus();
progDailog = ProgressDialog.show(this, "Please wait ...", "Retrieving data ...", true, true);
vvItemVideo.setOnPreparedListener(new android.media.MediaPlayer.OnPreparedListener() {

    @Override
    public void onPrepared(android.media.MediaPlayer mp) {
        Log.e(TAG, "video is prepared");
        progDailog.dismiss();
        vvItemVideo.seekTo(position);
        vvItemVideo.start();
        final MyMediaController mc = new MyMediaController(ItemDetailActivity.this);
        vvItemVideo.setMediaController(mc);
        mc.setAnchorView(vvItemVideo);
        mc.show();
    }
});

任何幫助都將受到贊賞。

如果您真的不需要手動處理方向更改,請在清單中按如下所示定義您的活動。

    <activity
        android:name="youractivity"
        android:configChanges="screenSize|orientation"
        android:launchMode="singleTask" >
    </activity>

這將管理方向更改,您無需為此編寫代碼。

並在onConfigurationChanged方法中使用以下代碼:

LinearLayout.LayoutParams linear_layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
    linear_layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
} else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
    linear_layoutParams = new LinearLayout.LayoutParams(
    LinearLayout.LayoutParams.MATCH_PARENT, 250);
}
videoView.setLayoutParams(linear_layoutParams);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM