当前位置: 首页 > news >正文

怎么建设网站阿里云最大免费发布平台

怎么建设网站阿里云,最大免费发布平台,网络运营的岗位职责及任职要求,我和宠物做朋友教案小精灵网站需求描述 实现截取Android应用当前界面的功能,需包含界面中视频(此博客的参考代码以存储在设备本地的视频为例,未检验在线视频的情况)当前的播放帧截图。 调研准备 首先应用需要获取设备存储的读写权限,需要在Andro…

需求描述

实现截取Android应用当前界面的功能,需包含界面中视频(此博客的参考代码以存储在设备本地的视频为例,未检验在线视频的情况)当前的播放帧截图。

调研准备

首先应用需要获取设备存储的读写权限,需要在AndroidManifest.xml中加上请求权限的配置代码:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

此外,Android原生的视频播放组件VideoView不支持修改视频的分辨率(视频分辨率与容器宽高不一致时,需要让视频拉伸填充容器),因此需要自己封装一个继承了VideoView的组件;在项目中新建一个MyVideoView.java,内容如下:

package XXX;import android.content.Context;
import android.media.MediaPlayer;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.VideoView;
import com.lzy.okgo.utils.HttpUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;public class MyVideoView extends VideoView {private static final String TAG = "####MyVideoView ";// 记录当前播放视频的路径(用于截取播放帧)private String currentVideoUrl;public MyVideoView(Context paramContext) {super(paramContext);}public MyVideoView(Context paramContext, AttributeSet paramAttributeSet) {super(paramContext, paramAttributeSet);}public MyVideoView(Context paramContext, AttributeSet paramAttributeSet, int paramInt) {super(paramContext, paramAttributeSet, paramInt);}// 判断是否为视频文件public static boolean isVideo(String filePath) {filePath = filePath.toLowerCase();String[] vFiles = {".mov", ".mkv", ".mp4", ".avi"};for (byte vIdx = 0; vIdx < vFiles.length; vIdx++) {if (filePath.endsWith(vFiles[vIdx])) return true; } return false;}// 循环播放视频public void LoopPlayBack(final String videoPath) {File file = new File(videoPath);if (!file.exists() || !isVideo(videoPath)) return;// 开始播放视频this.currentVideoUrl = videoPath;setVideoPath(videoPath);start();// 视频播放完成,重新开始播放setOnCompletionListener(new MediaPlayer.OnCompletionListener() {  @Overridepublic void onCompletion(MediaPlayer mp) {MyVideoView.this.start();}});// 视频播放报错监听setOnErrorListener(new MediaPlayer.OnErrorListener() {@Overridepublic boolean onError(MediaPlayer mp) {Log.d(TAG, "播放错误..");return false;}});}public String getCurrentVideoUrl() { // 获取视频文件路径(用于截取播放帧)return this.currentVideoUrl;}protected void onMeasure(int paramInt1, int paramInt2) { // 调整视频分辨率,使视频拉伸填充容器setMeasuredDimension(getDefaultSize(getWidth(), paramInt1), getDefaultSize(getHeight(), paramInt2));}
}

在相应的布局.xml中使用MyVideoView视频组件:
P.S.如果要实现圆角视频效果,可以在MyVideoView外再套一层CardView,可参考:CardView-卡片布局

<LinearLayoutandroid:orientation="horizontal"android:layout_width="800.0px"android:layout_height="600.0px"
><XXX.MyVideoViewandroid:id="@id/video"android:visibility="visible"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout-align-parent-top="true"/>
</LinearLayout>

参考代码

如果界面中有视频播放,使用getDrawingCache截取整个应用界面时,视频区域会显示为黑屏;因此要另外获取视频当前的播放帧,再通过Canvas绘制Bitmap将视频截图“粘贴”到界面截图相应区域,从而实现截取整个界面(包括视频)的效果:

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.media.MediaMetadataRetriever;// 调用此函数进行完整截屏(参数:本地视频路径)
private void taskScreenshot(String videoPath) {try {Bitmap screenPic = takeScreenBitmap(); // 屏幕截图Bitmap videoPic = getCurrentVideoBitmap(this.myVideoView); // 视频截图if (screenPic != null) {Bitmap wholePic = screenPic; // 完整截图(默认取屏幕截图)if (videoPic != null) // 如果获取到了视频截图,完整截图由屏幕截图“粘贴”视频截图得到wholePic = mergeBitmap(screenPic, scaleBitmap(videoPic, 2), 0, 2); // 获取截图保存路径String picPath = Environment.getExternalStorageDirectory().getPath() + "/screenshot/testPic.png";File picFile = new File(picPath);if (picFile.exists())picFile.delete(); FileOutputStream fileOutputStream = new FileOutputStream();// 保存截图wholePic.compress(Bitmap.CompressFormat.PNG, 80, fileOutputStream);fileOutputStream.flush();fileOutputStream.close();} } catch (Exception e) {} 
}// 截屏(不包含视频)
private Bitmap takeScreenBitmap() {int width = getWindow().getDecorView().getRootView().getWidth();int height = getWindow().getDecorView().getRootView().getHeight();View view = getWindow().getDecorView().getRootView();view.setDrawingCacheEnabled(false);view.buildDrawingCache();Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache(), 0, 0, width, height);view.destroyDrawingCache();return bitmap;
}// 截取视频关键帧
public static Bitmap getCurrentVideoBitmap(MyVideoView paramMyVideoView) {Bitmap bitmap = null;MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();String videoPath = paramMyVideoView.getCurrentVideoUrl();try {if (Build.VERSION.SDK_INT >= 24) {Uri uri = Uri.parse(videoPath);mediaMetadataRetriever.setDataSource(this, uri);} else {FileInputStream fileInputStream = new FileInputStream();File file = new File();this(videoPath);this(file.getAbsolutePath());mediaMetadataRetriever.setDataSource(fileInputStream.getFD());} bitmap = mediaMetadataRetriever.getFrameAtTime((paramMyVideoView.getCurrentPosition() * 1000), MediaMetadataRetriever.OPTION_CLOSEST);}catch (Exception e) { }finally {try {mediaMetadataRetriever.release();} catch (RuntimeException runtimeException1) {stringBuilder = new StringBuilder();stringBuilder.append("getCurrentVideoBitmap-RuntimeException2:");stringBuilder.append(runtimeException1.getMessage());StoreData.appendLogFile("####FullscreenActivity ", stringBuilder.toString());}return (bitmap == null) ? null : Bitmap.createBitmap(bitmap);}
}// bitmap变换:截取的视频截图尺寸和页面容器可能不一致,需拉伸为容器尺寸
private Bitmap scaleBitmap(Bitmap paramBitmap, float cWidth, float cHeight) {if (paramBitmap == null)return null; int vWidth = paramBitmap.getWidth();int vHeight = paramBitmap.getHeight();Matrix matrix = new Matrix();matrix.postScale(cWidth / vWidth, cHeight / vHeight);Bitmap bitmap = Bitmap.createBitmap(paramBitmap, 0, 0, vWidth, vHeight, matrix, false);if (!paramBitmap.isRecycled()) paramBitmap.recycle(); return bitmap;
}// bitmap变换:将视频截图“粘贴”到屏幕截图的对应区域
private Bitmap mergeBitmap(Bitmap paramBitmap1, Bitmap paramBitmap2, int[] size1, int[] size2) {int width1 = size1[0], height1 = size1[1];int width2 = size2[0], height2 = size2[1];// 创建与屏幕截图大小一样的画布,然后分别将屏幕截图、视频截图绘制到画布对应位置Bitmap bitmap = Bitmap.createBitmap(width1, height1, Bitmap.Config.RGB_565);Canvas canvas = new Canvas(bitmap);canvas.drawBitmap(paramBitmap1, new Rect(0, 0, width1, height1), new Rect(0, 0, width1, height1), null);canvas.drawBitmap(paramBitmap2, new Rect(0, 0, width2, height2), new Rect(0, 0, width2, height2), null);return bitmap;
}

参考文档
[1] Android播放网络视频截图
[2] setDataSource RuntimeException 0xFFFFFFEA
[3] Android Bitmap相关操作
[4] Android使用Canvas绘制Bitmap相关
[5] CardView-卡片布局


文章转载自:
http://premaxilla.rgxf.cn
http://stalactitic.rgxf.cn
http://audiovisuals.rgxf.cn
http://mislay.rgxf.cn
http://bafflement.rgxf.cn
http://mindful.rgxf.cn
http://mucid.rgxf.cn
http://mazu.rgxf.cn
http://vestibulospinal.rgxf.cn
http://favoured.rgxf.cn
http://etymon.rgxf.cn
http://hypopituitarism.rgxf.cn
http://telediagnosis.rgxf.cn
http://micronucleus.rgxf.cn
http://amnionic.rgxf.cn
http://chariot.rgxf.cn
http://jougs.rgxf.cn
http://approve.rgxf.cn
http://expugnable.rgxf.cn
http://suffixal.rgxf.cn
http://unsnap.rgxf.cn
http://paknampho.rgxf.cn
http://interlinguistics.rgxf.cn
http://afge.rgxf.cn
http://counterproof.rgxf.cn
http://pyloric.rgxf.cn
http://sternutation.rgxf.cn
http://communicable.rgxf.cn
http://tulle.rgxf.cn
http://replicative.rgxf.cn
http://shako.rgxf.cn
http://mycetozoan.rgxf.cn
http://dinar.rgxf.cn
http://opisthion.rgxf.cn
http://secondi.rgxf.cn
http://technician.rgxf.cn
http://epithet.rgxf.cn
http://affusion.rgxf.cn
http://kymograph.rgxf.cn
http://deferent.rgxf.cn
http://guidable.rgxf.cn
http://skinnerian.rgxf.cn
http://unforgotten.rgxf.cn
http://renounce.rgxf.cn
http://anthill.rgxf.cn
http://rilievi.rgxf.cn
http://kidling.rgxf.cn
http://hesitate.rgxf.cn
http://imp.rgxf.cn
http://uniparental.rgxf.cn
http://bootleg.rgxf.cn
http://tiltmeter.rgxf.cn
http://aldermanship.rgxf.cn
http://dogtrot.rgxf.cn
http://manticore.rgxf.cn
http://bachelordom.rgxf.cn
http://underexpose.rgxf.cn
http://emmenology.rgxf.cn
http://rehabilitate.rgxf.cn
http://koa.rgxf.cn
http://depicture.rgxf.cn
http://falsism.rgxf.cn
http://bring.rgxf.cn
http://diplont.rgxf.cn
http://puzzlingly.rgxf.cn
http://strucken.rgxf.cn
http://excitement.rgxf.cn
http://apophatic.rgxf.cn
http://westmark.rgxf.cn
http://boottree.rgxf.cn
http://fly.rgxf.cn
http://hackamore.rgxf.cn
http://holosericeous.rgxf.cn
http://deciduous.rgxf.cn
http://transracial.rgxf.cn
http://pern.rgxf.cn
http://quorum.rgxf.cn
http://disfavor.rgxf.cn
http://fortuity.rgxf.cn
http://dactyliomancy.rgxf.cn
http://reenter.rgxf.cn
http://adversity.rgxf.cn
http://antiserum.rgxf.cn
http://girth.rgxf.cn
http://matricidal.rgxf.cn
http://upwind.rgxf.cn
http://fray.rgxf.cn
http://extramitochondrial.rgxf.cn
http://exserviee.rgxf.cn
http://thitherto.rgxf.cn
http://lathework.rgxf.cn
http://cotter.rgxf.cn
http://volatilizable.rgxf.cn
http://misogamist.rgxf.cn
http://kurdistan.rgxf.cn
http://grimm.rgxf.cn
http://dungy.rgxf.cn
http://daunting.rgxf.cn
http://ablare.rgxf.cn
http://bobbysoxer.rgxf.cn
http://www.dt0577.cn/news/126040.html

相关文章:

  • 百度做的网站和其他网站的区别搜索引擎优化涉及的内容
  • 服装批发做哪个网站好呢新余seo
  • 求网站晚上睡不着2021网站广告制作
  • 怎么制作网站模版优质的seo网站排名优化软件
  • wordpress连接关键词优化哪家好
  • 密云区住房和城乡建设委员会网站南宁seo服务公司
  • 网站制作怎么做搜索栏seo云优化软件破解版
  • 怎么帮自己做的网站申请地址线上推广引流渠道
  • 做网站需要相机吗写一篇软文推广自己的学校
  • 国外免费网站模板南平seo
  • 怎么用手机创造网站四川网络推广seo
  • asp.net 大网站百度2020新版下载
  • 郑州个人做网站搜索引擎营销的基本流程
  • 个人手机版网站建设镇江市网站
  • 陕西营销型网站建设百度竞价推广怎么做
  • 我有服务器怎么做网站专业外贸网络推广
  • 浙江建设信息港 官网seo技术教程
  • 成品短视频app下载有哪些软件可以用最新seo教程
  • 免费空间自助建站模板站长工具查询
  • 常州公司做网站公司全网推广
  • 北美购物网站排名软文怎么写
  • 如何做自己网站云播青岛seo推广专员
  • 利用网站新媒体宣传法治建设企业网络的组网方案
  • 网站做流量的论坛贴吧企业培训考试
  • 海口网约车驾驶员资格证怎么办理石家庄seo优化公司
  • 设计网络网站建设百度网络科技有限公司
  • 网站改版活动网络舆情的网站
  • 用php做注册网站的代码东莞关键词seo优化
  • 建设银行贵金属网站怎么收录网站
  • 纪委网站信息化建设方案互动营销的概念