/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.abrantix.roundedvideo;
import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.SurfaceTexture;
import android.media.MediaPlayer;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Surface;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
/**
* This class has been adapted from
*
* https://code.google.com/p/android-source-browsing/source/browse/tests/tests/media/src/
* android/media/cts/VideoSurfaceView.java?repo=platform--cts
*
* {@link GLSurfaceView} subclass that displays video on the screen with the ability
* to round its corners.
*
* It creates a GL texture and from that generates a {@link SurfaceTexture} and an
* associated {@link Surface} which it binds to a given
* {@link MediaPlayer}. The {@link MediaPlayer} will draw the decoded
* video frames directly on to the GL texture which afterwards is rendered on the screen mapped to
* a given (rounded corner) geometry.
*
* To set adjust the rounded corners use {@link #setCornerRadius(float, float, float, float)}.
*
*/
public class VideoSurfaceView extends GLSurfaceView {
private static final String TAG = "VideoSurfaceView";
private static final boolean USE_MULTI_SAMPLING = true;
VideoRenderer mRenderer;
MediaPlayer mMediaPlayer = null;
MultiSampleEGLConfigChooser mMultiSamplingConfigChooser;
public VideoSurfaceView(Context context) {
super(context);
init(new VideoRenderer(this));
}
public VideoSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
init(new VideoRenderer(this));
}
VideoSurfaceView(Context context, VideoRenderer videoRender) {
super(context);
init(videoRender);
}
private void init( VideoRenderer videoRender) {
setEGLContextClientVersion(2);
setupEGLConfig(true, USE_MULTI_SAMPLING);
if (USE_MULTI_SAMPLING && mMultiSamplingConfigChooser != null) {
videoRender.setUsesCoverageAa(mMultiSamplingConfigChooser.usesCoverageAa());
}
mRenderer = videoRender;
setRenderer(mRenderer);
setRenderMode(RENDERMODE_WHEN_DIRTY);
}
/**
* Make sure the {@link android.view.SurfaceHolder} pixel format matches your EGL configuration.
*
* @param translucent true if the view should show views below if parts of the view area are
* transparent. Has performance implications.
* @param multisampling true if the GL Surface should perform multi-sampling. This avoids hard
* edges on the geometry. Has performance implications.
*/
private void setupEGLConfig(boolean translucent, boolean multisampling) {
if (translucent) {
setZOrderOnTop(true);
if (multisampling) {
mMultiSamplingConfigChooser = new MultiSampleEGLConfigChooser();
setEGLConfigChooser(mMultiSamplingConfigChooser);
} else {
setEGLConfigChooser(8, 8, 8, 8, 16, 0);
}
this.getHolder().setFormat(PixelFormat.RGBA_8888);
} else {
if (multisampling) {
mMultiSamplingConfigChooser = new MultiSampleEGLConfigChooser();
setEGLConfigChooser(mMultiSamplingConfigChooser);
} else {
setEGLConfigChooser(5, 6, 5, 0, 16, 0);
}
this.getHolder().setFormat(PixelFormat.RGB_565);
}
}
public void setCornerRadius(float radius) {
setCornerRadius(radius, radius, radius, radius);
}
public void setCornerRadius(float topLeft, float topRight, float bottomRight,
float bottomLeft) {
mRenderer.setCornerRadius(topLeft, topRight, bottomRight, bottomLeft);
}
// TODO
public void setVideoAspectRatio(float aspectRatio) {
mRenderer.setVideoAspectRatio(aspectRatio);
}
@Override
public void onResume() {
queueEvent(new Runnable(){
public void run() {
mRenderer.setMediaPlayer(mMediaPlayer);
}});
super.onResume();
}
public void setMediaPlayer( MediaPlayer mediaPlayer) {
mMediaPlayer = mediaPlayer;
if (mRenderer != null) {
mRenderer.setMediaPlayer(mediaPlayer);
}
}
private static class VideoRenderer
implements Renderer, SurfaceTexture.OnFrameAvailableListener {
private static String TAG = "VideoRender";
private static final int FLOAT_SIZE_BYTES = 4;
private static final int SHORT_SIZE_BYTES = 2;
private static final int TRIANGLE_VERTICES_DATA_STRIDE_BYTES = 5 * FLOAT_SIZE_BYTES;
private static final int TRIANGLE_VERTICES_DATA_POS_OFFSET = 0;
private static final int TRIANGLE_VERTICES_DATA_UV_OFFSET = 3;
private final boolean USE_DRAW_ELEMENTS = true;
private final String mVertexShader =
"uniform mat4 uMVPMatrix;\n" +
"uniform mat4 uSTMatrix;\n" +
"attribute vec4 aPosition;\n" +
"attribute vec4 aTextureCoord;\n" +
"varying vec2 vTextureCoord;\n" +
"void main() {\n" +
" gl_Position = uMVPMatrix * aPosition;\n" +
" vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n" +
"}\n";
private final String mFragmentShader =
"#extension GL_OES_EGL_image_external : require\n" +
"precision mediump float;\n" +
"varying vec2 vTextureCoord;\n" +
"uniform samplerExternalOES sTexture;\n" +
"void main() {\n" +
" gl_FragColor = texture2D(sTexture, vTextureCoord);\n" +
"}\n";
private float[] mMVPMatrix = new float[16];
private float[] mSTMatrix = new float[16];
private int mProgram;
private int mTextureID;
private int muMVPMatrixHandle;
private int muSTMatrixHandle;
private int maPositionHandle;
private int maTextureHandle;
private static int GL_TEXTURE_EXTERNAL_OES = 0x8D65;
private final GLSurfaceView mGLSurfaceView;
private MediaPlayer mMediaPlayer;
private SurfaceTexture mSurfaceTexture;
private boolean mUpdateSurface = false;
private float[] mTriangleVerticesData;
private short[] mTriangleIndicesData;
private FloatBuffer mTriangleVertices;
private ShortBuffer mTriangleIndices;
private RectF mRoundRadius = new RectF();
private GLRoundedGeometry mRoundedGeometry;
private final Point mViewPortSize = new Point();
private final RectF mViewPortGLBounds;
private boolean mUsesCoverageAa = false;
public VideoRenderer( GLSurfaceView view) {
没有合适的资源?快使用搜索试试~ 我知道了~
android surfaceview 悬浮窗圆角 windowmanager
共75个文件
xml:25个
kt:17个
webp:10个
需积分: 0 0 下载量 48 浏览量
2024-02-01
22:48:37
上传
评论
收藏 74.6MB ZIP 举报
温馨提示
android surfaceview圆角
资源推荐
资源详情
资源评论
收起资源包目录
归档.zip (75个子文件)
gradle.properties 1KB
gradle
wrapper
gradle-wrapper.jar 58KB
gradle-wrapper.properties 230B
lib
src
main
java
com
example
lib
MyClass.java 334B
build.gradle 143B
.gitignore 6B
app
.DS_Store 6KB
src
.DS_Store 6KB
androidTest
java
com
example
mytest
ExampleInstrumentedTest.kt 663B
test
java
com
example
mytest
ExampleUnitTest.kt 342B
main
java
com
abrantix
roundedvideo
VideoSurfaceView.java 19KB
MultiSampleEGLConfigChooser.java 5KB
GLRoundedGeometry.java 15KB
example
MainActivity.kt 7KB
WickedGradientDrawable.java 3KB
fuusy
floatwindow
MainActivity.kt 812B
MyOutline.java 448B
FloatWindowManager.kt 10KB
VideoPlayActivity.kt 874B
CustonVideoLayout.java 2KB
App.kt 297B
example
mytest
CountDownActivity.kt 1KB
MainActivity.kt 5KB
DownAdapter.kt 1KB
MyApplication.kt 328B
floating
FloatingView.kt 3KB
FloatingManager.kt 7KB
FloatingSerivice.kt 1KB
DownTextView.kt 998B
imp
OnNavigationStateListener.kt 133B
DownBean.kt 64B
res
mipmap-xxhdpi
ic_launcher_round.webp 6KB
ic_launcher.webp 3KB
mipmap-hdpi
ic_launcher_round.webp 3KB
ic_launcher.webp 1KB
drawable-v24
ic_launcher_foreground.xml 2KB
mipmap-anydpi-v26
ic_launcher.xml 272B
ic_launcher_round.xml 272B
values-night
themes.xml 808B
mipmap-mdpi
ic_launcher_round.webp 2KB
ic_launcher.webp 982B
mipmap-xxxhdpi
ic_launcher_round.webp 8KB
ic_launcher.webp 4KB
mipmap-xhdpi
ic_launcher_round.webp 4KB
ic_launcher.webp 2KB
mipmap-anydpi-v33
ic_launcher.xml 343B
xml
data_extraction_rules.xml 551B
backup_rules.xml 478B
values
dimens.xml 262B
colors.xml 378B
style.xml 518B
strings.xml 68B
themes.xml 808B
layout
activity_count_down.xml 4KB
activity_round.xml 1KB
activity_video_play.xml 688B
view_floating.xml 929B
activity_float_window.xml 805B
item_down.xml 597B
activity_main.xml 2KB
layout_video_play.xml 352B
activity_video_play2.xml 838B
layout_float_window.xml 1KB
drawable
ic_launcher_background.xml 5KB
ic_baseline_close_24.xml 420B
raw
test.mp4 74.69MB
AndroidManifest.xml 2KB
proguard-rules.pro 750B
build.gradle 1KB
.gitignore 6B
gradlew.bat 3KB
build.gradle 295B
settings.gradle 338B
local.properties 347B
gradlew 6KB
共 75 条
- 1
资源评论
猪猪上
- 粉丝: 10
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功