038-第三代软件开发-简易视频播放器-自定义Slider (二)

本文主要是介绍038-第三代软件开发-简易视频播放器-自定义Slider (二),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

头图

第三代软件开发-简易视频播放器-自定义Slider (二)

文章目录

  • 第三代软件开发-简易视频播放器-自定义Slider (二)
    • 项目介绍
    • 简易视频播放器
    • 自定义Slider (二)
      • 横向
      • 纵向

关键字: QtQml关键字3关键字4关键字5

项目介绍

欢迎来到我们的 QML & C++ 项目!这个项目结合了 QML(Qt Meta-Object Language)和 C++ 的强大功能,旨在开发出色的用户界面和高性能的后端逻辑。

在项目中,我们利用 QML 的声明式语法和可视化设计能力创建出现代化的用户界面。通过直观的编码和可重用的组件,我们能够迅速开发出丰富多样的界面效果和动画效果。同时,我们利用 QML 强大的集成能力,轻松将 C++ 的底层逻辑和数据模型集成到前端界面中。

在后端方面,我们使用 C++ 编写高性能的算法、数据处理和计算逻辑。C++ 是一种强大的编程语言,能够提供卓越的性能和可扩展性。我们的团队致力于优化代码,减少资源消耗,以确保我们的项目在各种平台和设备上都能够高效运行。

无论您是对 QML 和 C++ 开发感兴趣,还是需要我们为您构建复杂的用户界面和后端逻辑,我们都随时准备为您提供支持。请随时联系我们,让我们一同打造现代化、高性能的 QML & C++ 项目!

重要说明☝

☀该专栏在第三代软开发更新完将涨价

简易视频播放器

其实咱们在前面屏保哪里已经搞过视频文件播放了,只是哪里没有进度条,也没有时间线,也不能控制播放暂停,今天我们就是把这些再加上去。如下图所示,这里因为原始录制的Gif 太大,无法上传,所以做了减帧处理,看着有点卡顿了。

这里咱就是直接上代码吧;

import QtQuick 2.15
import QtMultimedia 5.15
import QtQuick.Layouts 1.15                     // 布局需要
import QtQuick.Controls 2.15
Rectangle
{property string videoSource: "file"property bool fullScreen: falseid:rootcolor: "#000000"anchors.centerIn: parentwidth: 720height: 480visible: falseSoundEffect {id: playSoundsource: "qrc:/Audio/T_Resource/T_Audio/T_Base/buttonTach.wav"}//    Video//    {//        id:video_show//        anchors.fill: parent//        loops: MediaPlayer.Infinite//        source: root.videoSource//    }MediaPlayer{id:media_videosource: videoSource                 // 绝对路径loops: MediaPlayer.Infinitevolume: 0.5}VideoOutput{id:out_putanchors.fill: parentsource: media_video}RowLayout{id:layout_menuanchors.left: parent.leftanchors.right: parent.rightanchors.bottom: parent.bottomheight: 26spacing: 20Item{width: 26height: 20Image {anchors.centerIn: parentheight: 26fillMode: Image.PreserveAspectFitsource: (media_video.playbackState === MediaPlayer.PlayingState ) ? "qrc:/Video/T_Resource/T_Image/Vidoe/zt.png" : "qrc:/Video/T_Resource/T_Image/Vidoe/bf.png"}MouseArea{anchors.fill: parentonClicked: (media_video.playbackState === MediaPlayer.PlayingState ) ? media_video.pause() : media_video.play();}}Item {implicitWidth: 50Text {anchors.centerIn: parentfont.pixelSize: 20color: "#FFFFFF"text: {// 创建变量获取时间当前播放位置,单位毫秒var milliseconds = media_video.position// 创建变量,将当前播放位置的毫秒转换为分钟,并向下取舍var minutes = Math.floor(milliseconds / 60000)// 获取不足 60秒的毫秒数milliseconds -= minutes * 60000// 创建变量,不足60秒的毫秒数转换为秒var seconds = milliseconds / 1000// 进行四舍五入seconds = Math.round(seconds)// 判断秒数是否小于10秒,来输出时间格式,最终格式为:mm:ssif(seconds < 10)return minutes + ":0" + secondselsereturn minutes + ":" + seconds}}}Slider{id:durationTimeSliderLayout.fillWidth: truevalue: media_video.position / media_video.durationbackground: Rectangle{x: durationTimeSlider.leftPaddingy: durationTimeSlider.topPadding + durationTimeSlider.availableHeight / 2 - height / 2implicitHeight: 4implicitWidth: 200width: durationTimeSlider.availableWidthheight: implicitHeightradius: 2color: "#F0F0F0"    // 进度条背景颜色// 视频已经播放的区域Rectangle{width: durationTimeSlider.visualPosition * parent.widthheight: parent.heightcolor: "#36ABDF"    // 进度条已经走完的颜色radius: 2}}// 滑块样式handle: Rectangle{antialiasing: truex: durationTimeSlider.leftPadding + durationTimeSlider.visualPosition* (durationTimeSlider.availableWidth - width)y: durationTimeSlider.topPadding + durationTimeSlider.availableHeight / 2 - height / 2implicitWidth: 20implicitHeight: 20radius: 10border.color: "#bdbebf"    // 滑块边框颜色// 判断滑块按压状态,设置不同的颜色color: durationTimeSlider.pressed ? "#B0C4DE" : "#F0F0F0"// 滑块中心的区域,我这里设置了透明Rectangle{width: 4height: 4radius: 2color: "transparent"anchors.centerIn: parent}}property real index: 0property bool changed: false// 滑块移动时,将 index 设置为滑块当前位置onMoved: {if(pressed){index = position}}onPressedChanged: {if(pressed === true){changed = true}else if (changed === true){media_video.seek(index * media_video.duration)changed = false}}}Item {implicitWidth: 50Text {anchors.centerIn: parentfont.pixelSize: 20color: "#FFFFFF"text: {var millseconds = media_video.duration.valueOf()var minutes = Math.floor(millseconds / 60000)millseconds -= minutes * 6000var secounds = millseconds / 1000secounds = Math.round(secounds)// 返回 mm : ss 格式时间if(secounds < 10)return minutes + ":0" + secoundselsereturn minutes + ":" + secounds}}}Item{id:item_volumewidth: 26height: 20Image {anchors.centerIn: parentheight: 26fillMode: Image.PreserveAspectFitsource: "qrc:/Video/T_Resource/T_Image/Vidoe/yl_z.png"}MouseArea{anchors.fill: parentonClicked: item_volum.visible = !item_volum.visible}}Item{width: 26height: 20Image {anchors.centerIn: parentheight: 26fillMode: Image.PreserveAspectFitsource: fullScreen ? "qrc:/Video/T_Resource/T_Image/Vidoe/sx.png" :"qrc:/Video/T_Resource/T_Image/Vidoe/qp.png"}MouseArea{anchors.fill: parentonClicked: root.fullScreen = !root.fullScreen}}}Item {id:item_volumwidth: 42height: 235visible: falseanchors.bottom: layout_menu.topanchors.right: layout_menu.rightanchors.rightMargin: 36Text {anchors.top: parent.topanchors.horizontalCenter: parent.horizontalCenterfont.pixelSize: 20color: "#36ABDF"text: (volumeSlider.value * 100).toFixed(0)}Slider{id:volumeSliderwidth: 42height: 220from:0.0to:1.0stepSize: 0.01value: media_video.volumeanchors.bottom: parent.bottomanchors.horizontalCenter: parent.horizontalCenterorientation:Qt.Verticalbackground: Rectangle{anchors.horizontalCenter: parent.horizontalCentery: volumeSlider.topPadding + volumeSlider.availableHeight / 2 - height / 2implicitHeight: 200implicitWidth: 4width: 4height: volumeSlider.availableHeightradius: 2color: "#F0F0F0"    // 进度条背景颜色// 视频已经播放的区域Rectangle{anchors.bottom: parent.bottomwidth: parent.widthheight: parent.height - volumeSlider.visualPosition * parent.heightcolor: "#36ABDF"    // 进度条已经走完的颜色radius: 2}}// 滑块样式handle: Rectangle{antialiasing: trueanchors.horizontalCenter: parent.horizontalCentery: volumeSlider.topPadding + volumeSlider.visualPosition* (volumeSlider.availableHeight - height)implicitWidth: 20implicitHeight: 20radius: 10border.color: "#bdbebf"    // 滑块边框颜色// 判断滑块按压状态,设置不同的颜色color: volumeSlider.pressed ? "#B0C4DE" : "#F0F0F0"// 滑块中心的区域,我这里设置了透明Rectangle{width: 4height: 4radius: 2color: "transparent"anchors.centerIn: parent}}onValueChanged: media_video.volume = value}}function play(){media_video.play();}function stop(){if((media_video.playbackState === MediaPlayer.PlayingState  || media_video.playbackState === MediaPlayer.PausedState))media_video.stop();}
}

自定义Slider (二)

横向

        Slider{id:durationTimeSliderLayout.fillWidth: truevalue: media_video.position / media_video.durationbackground: Rectangle{x: durationTimeSlider.leftPaddingy: durationTimeSlider.topPadding + durationTimeSlider.availableHeight / 2 - height / 2implicitHeight: 4implicitWidth: 200width: durationTimeSlider.availableWidthheight: implicitHeightradius: 2color: "#F0F0F0"    // 进度条背景颜色// 视频已经播放的区域Rectangle{width: durationTimeSlider.visualPosition * parent.widthheight: parent.heightcolor: "#36ABDF"    // 进度条已经走完的颜色radius: 2}}// 滑块样式handle: Rectangle{antialiasing: truex: durationTimeSlider.leftPadding + durationTimeSlider.visualPosition* (durationTimeSlider.availableWidth - width)y: durationTimeSlider.topPadding + durationTimeSlider.availableHeight / 2 - height / 2implicitWidth: 20implicitHeight: 20radius: 10border.color: "#bdbebf"    // 滑块边框颜色// 判断滑块按压状态,设置不同的颜色color: durationTimeSlider.pressed ? "#B0C4DE" : "#F0F0F0"// 滑块中心的区域,我这里设置了透明Rectangle{width: 4height: 4radius: 2color: "transparent"anchors.centerIn: parent}}property real index: 0property bool changed: false// 滑块移动时,将 index 设置为滑块当前位置onMoved: {if(pressed){index = position}}onPressedChanged: {if(pressed === true){changed = true}else if (changed === true){media_video.seek(index * media_video.duration)changed = false}}}

纵向

        Slider{id:volumeSliderwidth: 42height: 220from:0.0to:1.0stepSize: 0.01value: media_video.volumeanchors.bottom: parent.bottomanchors.horizontalCenter: parent.horizontalCenterorientation:Qt.Verticalbackground: Rectangle{anchors.horizontalCenter: parent.horizontalCentery: volumeSlider.topPadding + volumeSlider.availableHeight / 2 - height / 2implicitHeight: 200implicitWidth: 4width: 4height: volumeSlider.availableHeightradius: 2color: "#F0F0F0"    // 进度条背景颜色// 视频已经播放的区域Rectangle{anchors.bottom: parent.bottomwidth: parent.widthheight: parent.height - volumeSlider.visualPosition * parent.heightcolor: "#36ABDF"    // 进度条已经走完的颜色radius: 2}}// 滑块样式handle: Rectangle{antialiasing: trueanchors.horizontalCenter: parent.horizontalCentery: volumeSlider.topPadding + volumeSlider.visualPosition* (volumeSlider.availableHeight - height)implicitWidth: 20implicitHeight: 20radius: 10border.color: "#bdbebf"    // 滑块边框颜色// 判断滑块按压状态,设置不同的颜色color: volumeSlider.pressed ? "#B0C4DE" : "#F0F0F0"// 滑块中心的区域,我这里设置了透明Rectangle{width: 4height: 4radius: 2color: "transparent"anchors.centerIn: parent}}onValueChanged: media_video.volume = value}

这部分qml 代码很好懂,没有啥需要注意的吧,这里需要注意的就是一部分

    MediaPlayer{id:media_videosource: videoSource                 // 绝对路径loops: MediaPlayer.Infinitevolume: 0.5}VideoOutput{id:out_putanchors.fill: parentsource: media_video}

其实我最开始是用了Video组件的,但是再全屏的时候遇到问题,就是画面不会跟着全屏,应该是哪里跟着改下就可,不过我没有时间处理,这个功能就是播放一下宣教视频和宣传视频,所以目前不会有太多的精力放在这里。


博客签名2021

这篇关于038-第三代软件开发-简易视频播放器-自定义Slider (二)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/297840

相关文章

如何自定义一个log适配器starter

《如何自定义一个log适配器starter》:本文主要介绍如何自定义一个log适配器starter的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录需求Starter 项目目录结构pom.XML 配置LogInitializer实现MDCInterceptor

Druid连接池实现自定义数据库密码加解密功能

《Druid连接池实现自定义数据库密码加解密功能》在现代应用开发中,数据安全是至关重要的,本文将介绍如何在​​Druid​​连接池中实现自定义的数据库密码加解密功能,有需要的小伙伴可以参考一下... 目录1. 环境准备2. 密码加密算法的选择3. 自定义 ​​DruidDataSource​​ 的密码解密3

spring-gateway filters添加自定义过滤器实现流程分析(可插拔)

《spring-gatewayfilters添加自定义过滤器实现流程分析(可插拔)》:本文主要介绍spring-gatewayfilters添加自定义过滤器实现流程分析(可插拔),本文通过实例图... 目录需求背景需求拆解设计流程及作用域逻辑处理代码逻辑需求背景公司要求,通过公司网络代理访问的请求需要做请

Spring Security自定义身份认证的实现方法

《SpringSecurity自定义身份认证的实现方法》:本文主要介绍SpringSecurity自定义身份认证的实现方法,下面对SpringSecurity的这三种自定义身份认证进行详细讲解,... 目录1.内存身份认证(1)创建配置类(2)验证内存身份认证2.JDBC身份认证(1)数据准备 (2)配置依

基于Python和MoviePy实现照片管理和视频合成工具

《基于Python和MoviePy实现照片管理和视频合成工具》在这篇博客中,我们将详细剖析一个基于Python的图形界面应用程序,该程序使用wxPython构建用户界面,并结合MoviePy、Pill... 目录引言项目概述代码结构分析1. 导入和依赖2. 主类:PhotoManager初始化方法:__in

用js控制视频播放进度基本示例代码

《用js控制视频播放进度基本示例代码》写前端的时候,很多的时候是需要支持要网页视频播放的功能,下面这篇文章主要给大家介绍了关于用js控制视频播放进度的相关资料,文中通过代码介绍的非常详细,需要的朋友可... 目录前言html部分:JavaScript部分:注意:总结前言在javascript中控制视频播放

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

使用Sentinel自定义返回和实现区分来源方式

《使用Sentinel自定义返回和实现区分来源方式》:本文主要介绍使用Sentinel自定义返回和实现区分来源方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Sentinel自定义返回和实现区分来源1. 自定义错误返回2. 实现区分来源总结Sentinel自定

如何自定义Nginx JSON日志格式配置

《如何自定义NginxJSON日志格式配置》Nginx作为最流行的Web服务器之一,其灵活的日志配置能力允许我们根据需求定制日志格式,本文将详细介绍如何配置Nginx以JSON格式记录访问日志,这种... 目录前言为什么选择jsON格式日志?配置步骤详解1. 安装Nginx服务2. 自定义JSON日志格式各

Android自定义Scrollbar的两种实现方式

《Android自定义Scrollbar的两种实现方式》本文介绍两种实现自定义滚动条的方法,分别通过ItemDecoration方案和独立View方案实现滚动条定制化,文章通过代码示例讲解的非常详细,... 目录方案一:ItemDecoration实现(推荐用于RecyclerView)实现原理完整代码实现