Commit 3f2806c7 authored by jiangjiantao's avatar jiangjiantao

视频背景动态模糊

parent c2231a10
apply plugin: 'com.android.library' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 28 compileSdkVersion 28
......
...@@ -15,18 +15,18 @@ ...@@ -15,18 +15,18 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<!-- <activity--> <activity
<!-- android:name=".MainActivity"--> android:name=".MainActivity"
<!-- android:configChanges="orientation|keyboardHidden|screenSize|keyboard|navigation"--> android:configChanges="orientation|keyboardHidden|screenSize|keyboard|navigation"
<!-- android:exported="true"--> android:exported="true"
<!-- android:launchMode="singleTask"--> android:launchMode="singleTask"
<!-- android:screenOrientation="portrait">--> android:screenOrientation="portrait">
<!-- <intent-filter>--> <intent-filter>
<!-- <action android:name="android.intent.action.MAIN" />--> <action android:name="android.intent.action.MAIN" />
<!-- <category android:name="android.intent.category.LAUNCHER" />--> <category android:name="android.intent.category.LAUNCHER" />
<!-- </intent-filter>--> </intent-filter>
<!-- </activity>--> </activity>
<activity <activity
android:name=".DetailActivity" android:name=".DetailActivity"
......
...@@ -27,28 +27,29 @@ public class MainActivity extends AppCompatActivity { ...@@ -27,28 +27,29 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
banner = findViewById(R.id.banner); banner = findViewById(R.id.banner);
MediaBean mediaBean = new MediaBean(); // MediaBean mediaBean = new MediaBean();
mediaBean.setUrl("https://hh-oss-html.miyapay.com/hhops/picture/16045733014903c31992a674f.png"); // mediaBean.setUrl("https://hh-oss-html.miyapay.com/hhops/picture/16045733014903c31992a674f.png");
mediaBean.setType(TYPE_IMAGE); // mediaBean.setType(TYPE_IMAGE);
list.add(mediaBean); // list.add(mediaBean);
//
MediaBean mediaBean2 = new MediaBean(); // MediaBean mediaBean2 = new MediaBean();
mediaBean2.setUrl("https://hh-oss-html.miyapay.com/hhops/picture/1611112341654cffdd7b004bb.png"); // mediaBean2.setUrl("https://hh-oss-html.miyapay.com/hhops/picture/1611112341654cffdd7b004bb.png");
mediaBean2.setType(TYPE_IMAGE); // mediaBean2.setType(TYPE_IMAGE);
list.add(mediaBean2); // list.add(mediaBean2);
// String basePath = "http://miya-hz.oss-cn-shanghai.aliyuncs.com/huihua-test/face-pay/archive/"; // String basePath = "http://miya-hz.oss-cn-shanghai.aliyuncs.com/huihua-test/face-pay/archive/";
String basePath = Environment.getExternalStorageDirectory().getPath()+"/"; String basePath = Environment.getExternalStorageDirectory().getPath()+"/";
MediaBean mediaBean3 = new MediaBean(); MediaBean mediaBean3 = new MediaBean();
mediaBean3.setUrl(basePath+"shu.mp4"); mediaBean3.setUrl(basePath+"1637567422388875.mp4");
mediaBean3.setType(TYPE_VIDEO); mediaBean3.setType(TYPE_VIDEO);
mediaBean3.setLooping(true);
list.add(mediaBean3); list.add(mediaBean3);
MediaBean mediaBean4 = new MediaBean(); // MediaBean mediaBean4 = new MediaBean();
mediaBean4.setUrl(basePath+"heng.mp4"); // mediaBean4.setUrl(basePath+"heng.mp4");
mediaBean4.setType(TYPE_VIDEO); // mediaBean4.setType(TYPE_VIDEO);
list.add(mediaBean4); // list.add(mediaBean4);
banner.bindData(list); banner.bindData(list);
......
package com.widget.imagevideobanner.player;
import android.opengl.GLSurfaceView;
import com.shuyu.gsyvideoplayer.render.view.GSYVideoGLView;
/**
* 简单模糊
* Created by guoshuyu on 2017/9/17.
*/
public class CustomBlurEffect implements GSYVideoGLView.ShaderInterface {
private int countLevel = 5;
public CustomBlurEffect() {
}
public CustomBlurEffect(int countLevel) {
this.countLevel = countLevel;
}
public void setCountLevel(int countLevel) {
this.countLevel = countLevel;
}
@Override
public String getShader(GLSurfaceView mGlSurfaceView) {
return "#extension GL_OES_EGL_image_external : require\n" +
"precision mediump float;\n" +
"uniform samplerExternalOES sTexture; \n" +
" \n" +
"varying vec2 vTextureCoord;\n" +
"const float barrelPower = 0.5; \n" +
"const int num_iter = "+ countLevel +"; \n" +
"const float reci_num_iter_f = 1.0 / float(num_iter); \n" +
" \n" +
"vec2 barrelDistortion(vec2 coord, float amt) \n" +
"{ \n" +
" vec2 cc = coord - 0.5; \n" +
" float dist = dot(cc, cc); \n" +
" return coord + cc * dist * amt; \n" +
"} \n" +
" \n" +
"float sat( float t ) \n" +
"{ \n" +
" return clamp( t, 0.0, 1.0 ); \n" +
"} \n" +
" \n" +
"float linterp( float t ) { \n" +
" return sat( 1.0 - abs( 2.0*t - 1.0 ) ); \n" +
"} \n" +
" \n" +
"float remap( float t, float a, float b ) \n" +
"{ \n" +
" return sat( (t - a) / (b - a) ); \n" +
"} \n" +
" \n" +
"vec3 spectrum_offset( float t ) \n" +
"{ \n" +
" vec3 ret; \n" +
" float lo = step(t,0.5); \n" +
" float hi = 1.0-lo; \n" +
" float w = linterp( remap( t, 1.0/6.0, 5.0/6.0 ) ); \n" +
" ret = vec3(lo,1.0,hi) * vec3(1.0-w, w, 1.0-w); \n" +
" \n" +
" return pow( ret, vec3(1.0/2.2) ); \n" +
"} \n" +
" \n" +
"void main() \n" +
"{ \n" +
" vec2 uv=(gl_FragCoord.xy/vTextureCoord.xy); \n" +
" \n" +
" vec3 sumcol = vec3(0.0); \n" +
" vec3 sumw = vec3(0.0); \n" +
" for ( int i=0; i<num_iter;++i ) \n" +
" { \n" +
" float t = float(i) * reci_num_iter_f; \n" +
" vec3 w = spectrum_offset( t );\n" +
" sumw += w;\n" +
" sumcol += w * texture2D( sTexture, barrelDistortion(vTextureCoord, barrelPower*t ) ).rgb; \n" +
" }\n" +
" gl_FragColor = vec4(sumcol.rgb / sumw, 1.0); \n" +
"} ";
}
}
package com.widget.imagevideobanner.player;
import android.opengl.GLES20;
import android.opengl.Matrix;
import com.shuyu.gsyvideoplayer.render.effect.NoEffect;
import com.shuyu.gsyvideoplayer.render.glrender.GSYVideoGLViewSimpleRender;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
/**
* 铺满的双重播放
* 配合高斯模糊,可以实现,高斯拉伸视频铺满背景,替换黑色,前台正常比例播放
* https://github.com/CarGuo/GSYVideoPlayer/issues/1252
*/
public class GSYVideoGLViewCustomRender4 extends GSYVideoGLViewSimpleRender {
private int mProgram;
public GSYVideoGLViewCustomRender4() {
super();
}
@Override
public void onDrawFrame(GL10 glUnused) {
super.onDrawFrame(glUnused);
GLES20.glUseProgram(mProgram);
float[] transform = new float[16];
Matrix.setIdentityM(transform, 0);
Matrix.scaleM(transform, 0, (float) mCurrentViewWidth / mSurfaceView.getWidth(),
(float) mCurrentViewHeight / mSurfaceView.getHeight(), 1);
GLES20.glUniformMatrix4fv(getMuSTMatrixHandle(), 1, false, mSTMatrix, 0);
GLES20.glUniformMatrix4fv(getMuMVPMatrixHandle(), 1, false, transform, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
GLES20.glFinish();
}
@Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
super.onSurfaceCreated(glUnused, config);
mProgram = createProgram(getVertexShader(), new NoEffect().getShader(mSurfaceView));
}
@Override
public void initRenderSize() {
Matrix.scaleM(mMVPMatrix, 0, 1f, 1f, 1);
}
}
...@@ -2,18 +2,41 @@ package com.widget.imagevideobanner.view; ...@@ -2,18 +2,41 @@ package com.widget.imagevideobanner.view;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack; import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
import com.shuyu.gsyvideoplayer.video.GSYSampleADVideoPlayer; import com.shuyu.gsyvideoplayer.render.effect.AutoFixEffect;
import com.shuyu.gsyvideoplayer.render.effect.BarrelBlurEffect;
import com.shuyu.gsyvideoplayer.render.effect.BlackAndWhiteEffect;
import com.shuyu.gsyvideoplayer.render.effect.BrightnessEffect;
import com.shuyu.gsyvideoplayer.render.effect.ContrastEffect;
import com.shuyu.gsyvideoplayer.render.effect.CrossProcessEffect;
import com.shuyu.gsyvideoplayer.render.effect.DocumentaryEffect;
import com.shuyu.gsyvideoplayer.render.effect.FillLightEffect;
import com.shuyu.gsyvideoplayer.render.effect.GammaEffect;
import com.shuyu.gsyvideoplayer.render.effect.GaussianBlurEffect;
import com.shuyu.gsyvideoplayer.render.effect.GrainEffect;
import com.shuyu.gsyvideoplayer.render.effect.HueEffect;
import com.shuyu.gsyvideoplayer.render.effect.InvertColorsEffect;
import com.shuyu.gsyvideoplayer.render.effect.LamoishEffect;
import com.shuyu.gsyvideoplayer.render.effect.NoEffect;
import com.shuyu.gsyvideoplayer.render.effect.OverlayEffect;
import com.shuyu.gsyvideoplayer.render.effect.PosterizeEffect;
import com.shuyu.gsyvideoplayer.render.effect.SampleBlurEffect;
import com.shuyu.gsyvideoplayer.render.effect.SaturationEffect;
import com.shuyu.gsyvideoplayer.render.effect.SepiaEffect;
import com.shuyu.gsyvideoplayer.render.effect.SharpnessEffect;
import com.shuyu.gsyvideoplayer.render.effect.TemperatureEffect;
import com.shuyu.gsyvideoplayer.render.effect.VignetteEffect;
import com.shuyu.gsyvideoplayer.render.view.GSYVideoGLView;
import com.shuyu.gsyvideoplayer.utils.GSYVideoType;
import com.widget.imagevideobanner.R; import com.widget.imagevideobanner.R;
import com.widget.imagevideobanner.bean.MediaBean; import com.widget.imagevideobanner.bean.MediaBean;
import com.widget.imagevideobanner.log.BLogUtil; import com.widget.imagevideobanner.log.BLogUtil;
import com.widget.imagevideobanner.player.CustomBlurEffect;
import com.widget.imagevideobanner.player.GSYVideoGLViewCustomRender4;
import com.widget.imagevideobanner.player.IPlayTarget; import com.widget.imagevideobanner.player.IPlayTarget;
public class VideoSubView extends FrameLayout implements IPlayTarget { public class VideoSubView extends FrameLayout implements IPlayTarget {
...@@ -21,6 +44,8 @@ public class VideoSubView extends FrameLayout implements IPlayTarget { ...@@ -21,6 +44,8 @@ public class VideoSubView extends FrameLayout implements IPlayTarget {
private OnActionFinishListener mOnPageChangedListener; private OnActionFinishListener mOnPageChangedListener;
private SampleCoverVideo player; private SampleCoverVideo player;
private MediaBean mediaBean; private MediaBean mediaBean;
private float deep = 0.8f;
private final GSYSampleCallBack sampleCallBack = new GSYSampleCallBack(){ private final GSYSampleCallBack sampleCallBack = new GSYSampleCallBack(){
@Override @Override
...@@ -48,6 +73,11 @@ public class VideoSubView extends FrameLayout implements IPlayTarget { ...@@ -48,6 +73,11 @@ public class VideoSubView extends FrameLayout implements IPlayTarget {
player.setVideoAllCallBack(sampleCallBack); player.setVideoAllCallBack(sampleCallBack);
player.loadCoverImage(mediaBean.getCover(),0); player.loadCoverImage(mediaBean.getCover(),0);
player.setUp(mediaBean.getUrl(), true, null); player.setUp(mediaBean.getUrl(), true, null);
player.setEffectFilter(new BarrelBlurEffect());
// player.setEffectFilter(new GaussianBlurEffect(6.0f, GaussianBlurEffect.TYPEXY));
player.setCustomGLRenderer(new GSYVideoGLViewCustomRender4());
GSYVideoType.setRenderType(GSYVideoType.GLSURFACE);
player.setGLRenderMode(GSYVideoGLView.MODE_RENDER_SIZE);
player.setLooping(mediaBean.isLooping()); player.setLooping(mediaBean.isLooping());
BLogUtil.log("设置视频轮播是否循环模式="+mediaBean.isLooping()); BLogUtil.log("设置视频轮播是否循环模式="+mediaBean.isLooping());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment