这是关于 vitamio 使用的第二篇小文章,主要实现了如下效果:
竖屏的效果,给视频源指定了自己需要的高度:
旋转屏幕横屏之后的效果,使视频源充满屏幕:
接下来记录一下实现的步骤:
1、首先,我们写好布局文件,如下:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<io.vov.vitamio.widget.VideoView
android:id = "@+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity
{
String playUrl = "";
VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
Vitamio.initialize(this);
if(Vitamio.initialize(this))
{
videoView = (VideoView) findViewById(R.id.video);
videoView.setVideoURI(Uri.parse(playUrl));
MediaController controller = new MediaController(this);
videoView.setMediaController(controller);
videoView.start();
}
}
}
运行效果如下,图片略大。。。:
竖屏:
横屏:
可以看出,横屏之后即使 match_parent 也不能让视屏源全屏
首先,针对竖屏,我们先将 外层布局设置一个固定的值,即:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp">
...
</RelativeLayout>
此时效果如下:
可以看到视频源高度明显地变小,说明改变videoview的父布局高度是可行的,接着,我们将父布局的高度依然改为 match_parent,然后改变的是 videoview的高度,改成 20dp、100dp、200dp不等,即:
<RelativeLayout
android:layout_height="match_parent">
<io.vov.vitamio.widget.VideoView
android:id = "@+id