Vitamio 全屏视频查看
Posted
技术标签:
【中文标题】Vitamio 全屏视频查看【英文标题】:Vitamio full screen videoview 【发布时间】:2013-06-19 22:43:34 【问题描述】:我尝试使用 Vitamio 播放直播。我解决了一些问题,但是我无法解决这个问题。视频无法全屏播放。这些是我的代码。我希望你能帮帮我!谢谢你,对不起我的英语不好。
package com.uusoftware.tvizle;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
public class Trt extends Activity
VideoView videoView;
private void Trt1()
String httpLiveUrl = "rtmp://trt-i.mncdn.com/trt1/trt15";
videoView = (VideoView) findViewById(R.id.VideoView);
videoView.setVideoURI(Uri.parse(httpLiveUrl));
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.videolayout);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Trt1();
<?xml version="1.0" encoding="utf-8"?>`
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_
android:orientation="vertical" >
<io.vov.vitamio.widget.CenterLayout
android:layout_
android:layout_
android:orientation="vertical" >
<io.vov.vitamio.widget.VideoView
android:id="@+id/VideoView"
android:layout_
android:layout_
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</io.vov.vitamio.widget.CenterLayout>
</LinearLayout>
【问题讨论】:
【参考方案1】:将VideoView
放入RelativeLayout
并设置为:
<io.vov.vitamio.widget.VideoView
android:id="@+id/vitamioView"
android:layout_
android:layout_
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
【讨论】:
【参考方案2】:使用此方法在活动的 onCreate() 方法中拉伸视频视图
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
处理onConfigurationChange();
使用下面的代码
@Override
public void onConfigurationChanged(Configuration newConfig)
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
Log.e("On Config Change", "LANDSCAPE");
else
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
Log.e("On Config Change", "PORTRAIT");
在你的活动清单文件中也添加这个
android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
【讨论】:
【参考方案3】:if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
mVideoView.setVideoLayout(io.vov.vitamio.widget.VideoView.VIDEO_LAYOUT_STRETCH, 0);
else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
mVideoView.setVideoLayout(io.vov.vitamio.widget.VideoView.VIDEO_LAYOUT_ORIGIN, 0);
感谢@Qadir Hussain .它对我有用
【讨论】:
【参考方案4】:如果使用直播,那么 有一个名为“mediaplayer_2.xml”的直播布局文件
使用以下更改布局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_
android:orientation="vertical" >
<io.vov.vitamio.widget.CenterLayout
android:layout_
android:layout_
android:orientation="vertical" >
<SurfaceView
android:id="@+id/surface"
android:layout_
android:layout_
android:layout_gravity="center" >
</SurfaceView>
</io.vov.vitamio.widget.CenterLayout>
</LinearLayout>
通过这种方式我解决了我的问题。
【讨论】:
【参考方案5】:`包com.uusoftware.tvizle;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
public class Trt extends Activity
private VideoView mVideoView;
private void Trt1()
String httpLiveUrl = "rtmp://trt-i.mncdn.com/trt1/trt15";
mVideoView = (VideoView) findViewById(R.id.VideoView);
mVideoView.setVideoURI(Uri.parse(httpLiveUrl));
MediaController mediaController = new MediaController(this);
mVideoView.setMediaController(mediaController);
mVideoView.requestFocus();
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
mVideoView.start();
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.videolayout);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Trt1();
`
【讨论】:
以上是关于Vitamio 全屏视频查看的主要内容,如果未能解决你的问题,请参考以下文章
Android视频框架 Vitamio 打造自己的万能播放器