如何在肖像中以小尺寸播放视频 在风景中全屏?
Uri uri = Uri.parse(videoDetail.getVideoPath());
// Uri uri = Uri.parse("http://daily3gp.com/vids/747.3gp");
VideoView videoView = (VideoView) findViewById(R.id.videoPlayer);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
mediaController.setMediaPlayer(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.start();
答案 0 :(得分:2)
1>以横向和完整模式播放视频
添加您的清单文件
<activity
android:name=".youractivityname"
android:label="@string/app_name"
android:screenOrientation="landscape" >
并在.xml文件中添加此
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="fill" /></RelativeLayout>
2 - ;以小尺寸播放视频
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
无需使用android:screenOrientation
因为默认是纵向
并在您的xml文件中
`
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<RelativeLayout
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerVertical="true"
android:layout_marginLeft="40dp"
android:layout_toRightOf="@+id/textView1" >
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_gravity="fill" />
</RelativeLayout>
`
希望这会对你有帮助......
答案 1 :(得分:0)
尝试下面的事情:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
int left = videoView .getLeft();
int top = videoView .getTop();
int right = left + (width);
int botton = top + (height);
videoView .layout(left, top, right, bottom);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
int left = videoView .getLeft();
int top = videoView .getTop();
int right = left + (width / 2);
int botton = top + (height / 2);
videoView .layout(left, top, right, bottom);
}
}
答案 2 :(得分:0)
你可以试试这个。定义两个布局一个将使用全屏,另一个定义你想要的布局宽度高度和位置。并在活动类中定义这个代码。
`@覆盖
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
setContentView(R.layout.fullscreen);
}
else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
{
setContentView(R.layout.potrait);
}
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (getResources().getConfiguration().orientation == 1)
{
setContentView(R.layout.landscape);
}
if (getResources().getConfiguration().orientation == 2)
{
setContentView(R.layout.potrait);
}
}`
答案 3 :(得分:0)
发生的事情是当前的VideoView活动(风景)被破坏,由于screenOrientation配置已经更改而创建了一个新的VideoView活动(肖像),并且会立即去除(你可以在屏幕上看到效果)。尝试使用活动生命周期
看看它是否有效
`@Override
protected void onResume(){
mVideoView.resume();
super.onResume();
}
@覆盖 protected void onPause(){
mVideoView.suspend();
super.onPause();
}
@覆盖 protected void onDestroy(){
mVideoView.stopPlayback();
super.onDestroy();
}`