2012-10-29 35 views
12

nền tảng: đang phát triển trong Eclipse sử dụng SDK Android 16.Android VideoView không chơi Portrait Hướng

CÁC VẤN ĐỀ: Tôi có một yếu tố VideoView đó là nghĩa vụ để lấp đầy toàn bộ màn hình trong 480x800 (CHÂN DUNG ĐỊNH HƯỚNG) và nó chơi tốt, nhưng sẽ không định hướng chân dung. Nó dính trong chế độ phong cảnh và tỷ lệ khía cạnh được nghiêng để phù hợp theo cách đó.

GÌ Tôi đã cố gắng:

  • sử dụng android: screenOrientation = "chân dung" trong manifest
  • sử dụng android: định hướng = "thẳng đứng" trong các container và các VideoView tự
  • sử dụng setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ngay trước khi tôi gọi setContentView
  • cố gắng để thiết lập chiều rộng bố trí và chiều cao để 480dpx800dp thay vì fill_parent
  • cố gắng để thiết lập chiều rộng VideoView và chiều cao tới 480 x 800dp thay vì fill_parent
  • tắt tự động xoay màn hình

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

BỘ LUẬT:

@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(); 

    } 

câu hỏi: Không có gì tôi đã cố gắng đã thành công. Làm thế nào tôi có thể nhận được video 480x800 để phát theo hướng dọc?

Trả lời

0

Đây là những gì tôi đã kết thúc thực hiện:

Vấn đề là phiên bản hệ điều hành. Nếu đó là ICS (4.0) trở lên, nó sẽ phát video trên mặt của nó, vì vậy khi phát hiện android.os.Build.VERSION.SDK_INT của 14 hoặc cao hơn, tôi tải video được xây dựng trên mặt của nó để nó phát đúng cách.

Đây là giải pháp rất ngớ ngẩn và tôi chưa bao giờ thực sự có câu trả lời cho câu hỏi của mình. Video không nên phát như vậy.

0

Hãy thử điều này:

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

Hope this helps. Và cũng kiểm tra tệp kê khai của bạn.

+0

Sau khi thay đổi XML của tôi thành cài đặt ở trên, video vẫn phát theo chiều ngang và không theo chiều dọc. –

+0

@ RickS Sai lầm bạn đang thực hiện là xác định chiều cao cố định và chiều rộng cho bố cục và videoview của bạn. Chỉ cần sử dụng đối sánh mặc định của cha mẹ và chỉ cần viết android: screenOrientation = "portrait" vào hoạt động của tệp kê khai của bạn. –

+0

xóa android: screenOrientation khỏi hoạt động của bạn trong tệp kê khai – AMD

2

Bạn có chắc chắn video của mình là 480x800 và không phải 800x480 không? 800x480 là độ phân giải chuẩn, nếu bạn quay video ở chế độ dọc với điện thoại, đầu ra sẽ vẫn là 800x480 và để phát lại bình thường, video phải được xoay 90 độ. Những gì bạn mô tả là những gì sẽ xảy ra nếu bạn cố gắng phát video 800x480 trong videoView 480x800. Nếu đây là trường hợp bạn có thể xoay nó với phần mềm chỉnh sửa video như Windows Live Moviemaker hoặc iMovie nếu bạn đang dùng máy Mac.

+0

+1, hãy xem xét điều này. –

+0

Chúng tôi thực sự cắt video bằng phần mềm chỉnh sửa chuyên nghiệp Final Cut Pro ở một số độ phân giải, codec và định hướng khác nhau. Điều kỳ lạ là nó chơi tốt trên một máy tính bảng nhưng là lạ trên khác. –

+0

@ Rick S Máy tính bảng nào hoạt động và những gì đã làm –

1

Bạn đang sử dụng dp nơi bạn nên sử dụng 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" /> 

Hoặc cách khác (và tốt hơn) - chỉ cần sử dụng match_parent (hay 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" />