2015-12-01 145 views
-1

我試圖讓視頻播放爲背景。但我只能把它拿到屏幕的一半。所以,我需要將視頻延伸至16:9並將其旋轉90度以使其全屏。如何使視頻內的視頻旋轉90度並使其成爲全屏

我現在正在一個測試項目中工作。

MainActivity

public class MainActivity extends AppCompatActivity implements GestureOverlayView.OnGesturePerformedListener{ 

GestureLibrary gestureLib; 
VideoView vvRick; 
private Button btnTest; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

     gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures); 
     if (!gestureLib.load()) { 
      finish(); 
     } 
     GestureOverlayView gOverlay = 
       (GestureOverlayView) findViewById(R.id.gOverlay); 
     gOverlay.addOnGesturePerformedListener(this); 

     vvRick = (VideoView)findViewById(R.id.vvRick); 
     btnTest = (Button)findViewById(R.id.btnTest); 

     btnTest.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Toast.makeText(getApplicationContext(), "Workss!!", 
         Toast.LENGTH_LONG).show(); 
      } 
     }); 


    } 

    public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { 
     ArrayList<Prediction> predictions = gestureLib.recognize(gesture); 

     if (predictions.size() > 0 && predictions.get(0).score > 3.0) { 
      String result = predictions.get(0).name; 
      if ("turn".equalsIgnoreCase(result)) { 
       Toast.makeText(this, "Reverse", Toast.LENGTH_LONG).show(); 
      } else if ("easteregg".equalsIgnoreCase(result)) { 
       Toast.makeText(this, "EasterEgg", Toast.LENGTH_LONG).show(); 
       vvRick.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.rickroll)); 
       vvRick.start(); 
      } else{ 
       Toast.makeText(this, "FOUT", Toast.LENGTH_LONG).show(); 

      } 
     } 
    } 
} 

佈局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@+id/rlMain"> 

<VideoView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/vvRick" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:layout_gravity="center" 
    android:background="@android:color/transparent" /> 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/home_container" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/transparent"> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button Test" 
     android:id="@+id/btnTest" 
     android:layout_gravity="center" /> 

</FrameLayout> 

<android.gesture.GestureOverlayView 
    android:layout_width="fill_parent" 
    android:layout_height="200dp" 
    android:id="@+id/gOverlay" 
    android:minHeight="200dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentStart="true" 
    android:background="@android:color/transparent"></android.gesture.GestureOverlayView> 

+0

最簡單的將是旋轉'VideoView'。否則,你需要提取每個幀旋轉,然後將它們放在一起,以創建一個視頻等 –

+0

我試過,但現在它並沒有顯示。儘管我可以聽到視頻的聲音。 –

回答

0

VideoView不支持即使組合物基質中是否正確設置,並且用於旋轉屬性視頻的旋轉。

你可以做的是使用TextureView並設置其屬性rotation =「90」(例如)。然後它會旋轉框架,但縱橫比是你需要處理你自己的東西。爲了做到這一點,你可以使用textTureView.setScaleX((screenHeight * 1.0F)/屏幕寬度)

閱讀更多: https://stackoverflow.com/a/16490065/4503373