我正在使用VideoView&从资源中运行视频。
我想知道,有什么方法可以在运行视频时执行放大/缩小功能吗?
答案 0 :(得分:5)
好的我有这个问题并通过删除VideoView并用TextureView替换它来解决它。然后,您可以应用Matrix转换,其中包括许多选项,包括缩放。
我将使用的Matrix方法是postScale()
方法。您可以在帖子前后应用多种效果,您可以在文档中查看。
修改强>
以下是我们使用的正在运行的项目中的自定义VideoView。您可以在XML Layouts中对其进行十分转换,它有一个名为setMatrix()
的函数,它接受Matrix参数。原始代码由Alex Ross编写,然后我们对其进行修改以处理Matrix功能。
答案 1 :(得分:0)
您可以使用此链接https://github.com/father2sisters/scale_videoview
中提供的解决方案我已更新上述解决方案以处理方向更改。
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.view.ScaleGestureDetector.OnScaleGestureListener;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.widget.FrameLayout;
public class VideoZoomActivity extends AppCompatActivity {
int MIN_WIDTH;
private FrameLayout frameLayout;
private FrameLayout.LayoutParams mRootParam;
private VodView mVodView;
private ScaleGestureDetector mScaleGestureDetector;
private GestureDetector mGestureDetector;
DisplayMetrics dm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_zoom);
dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
MIN_WIDTH = dm.widthPixels;
Log.d("WIDTH==",MIN_WIDTH+"");
frameLayout = (FrameLayout)findViewById(R.id.root_view);
mRootParam = (FrameLayout.LayoutParams)frameLayout.getLayoutParams();
mVodView = (VodView) findViewById(R.id.vodView1);
mVodView.setVideoPath("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");
// set up gesture listeners
mScaleGestureDetector = new ScaleGestureDetector(this, new MyScaleGestureListener());
mGestureDetector = new GestureDetector(this, new MySimpleOnGestureListener());
mVodView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
mGestureDetector.onTouchEvent(event);
mScaleGestureDetector.onTouchEvent(event);
return true;
}
});
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
getWindowManager().getDefaultDisplay().getMetrics(dm);
MIN_WIDTH = dm.widthPixels;
mVodView.setFixedVideoSize(dm.widthPixels,dm.heightPixels);
mRootParam.width = dm.widthPixels;
mRootParam.height = dm.heightPixels;
getWindowManager().getDefaultDisplay().getMetrics(dm);
MIN_WIDTH = dm.widthPixels;
mVodView.setFixedVideoSize(dm.widthPixels,dm.heightPixels);
mRootParam.width = dm.widthPixels;
}
@Override
protected void onResume() {
mVodView.start();
super.onResume();
}
@Override
protected void onPause() {
mVodView.pause();
super.onPause();
}
private class MySimpleOnGestureListener extends SimpleOnGestureListener {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
if (mVodView == null)
return false;
if (mVodView.isPlaying())
mVodView.pause();
else
mVodView.start();
return true;
}
}
private class MyScaleGestureListener implements OnScaleGestureListener {
private int mW, mH;
@Override
public boolean onScale(ScaleGestureDetector detector) {
// scale our video view
mW *= detector.getScaleFactor();
mH *= detector.getScaleFactor();
if (mW < MIN_WIDTH) { // limits width
mW = mVodView.getWidth();
mH = mVodView.getHeight();
}
Log.d("onScale", "scale=" + detector.getScaleFactor() + ", w=" + mW + ", h=" + mH);
mVodView.setFixedVideoSize(mW, mH); // important
mRootParam.width = mW;
mRootParam.height = mH;
return true;
}
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
mW = mVodView.getWidth();
mH = mVodView.getHeight();
Log.d("onScaleBegin", "scale=" + detector.getScaleFactor() + ", w=" + mW + ", h=" + mH);
return true;
}
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
Log.d("onScaleEnd", "scale=" + detector.getScaleFactor() + ", w=" + mW + ", h=" + mH);
}
}
}
答案 2 :(得分:0)
使用此方法
video_player_view.getRotation();
进入水平模式,全屏显示视频
答案 3 :(得分:0)
找到了一个棘手的方法来实现所有视频播放器应用程序(mx 播放器、vlc)使用的相同缩放方法
您可以在屏幕宽度和高度的基础上更改视频视图布局参数。
zoom++;
if (zoom == 1) {
videoview1.setLayoutParams(new LinearLayout.LayoutParams(getDisplayWidthPixels(getApplicationContext()) + 500, getDisplayHeightPixels(getApplicationContext()) + 200));
Toast.showMessage(getApplicationContext(), "1");
}