This commit is contained in:
2024-10-16 16:53:39 +08:00
parent c1f78fe598
commit ac451d6403
28 changed files with 4148 additions and 607 deletions

View File

@@ -113,6 +113,8 @@ import commonList from '@/pages/component/commonComponents/list.vue'
Vue.component('common-list', commonList); Vue.component('common-list', commonList);
import commonVideoAliyun from '@/pages/component/commonComponents/video/AliPlayer.vue' import commonVideoAliyun from '@/pages/component/commonComponents/video/AliPlayer.vue'
Vue.component('common-list-aliyun', commonVideoAliyun); Vue.component('common-list-aliyun', commonVideoAliyun);
import commonVideoAudio from '@/pages/component/commonComponents/video/audio.vue'
Vue.component('common-list-audio', commonVideoAudio);
import commonVideo from '@/pages/component/commonComponents/video/index.vue' import commonVideo from '@/pages/component/commonComponents/video/index.vue'
Vue.component('common-video', commonVideo); Vue.component('common-video', commonVideo);

View File

@@ -116,11 +116,13 @@ export default {
}, },
}, },
// //
mounted() { this.platform = this.$platform; mounted() {
this.show = false; this.platform = this.$platform;
if (uni.getStorageSync("videoOssList")) { this.show = false;
this.videoOssList = JSON.parse(uni.getStorageSync("videoOssList")); if (uni.getStorageSync("videoOssList")) {
}}, this.videoOssList = JSON.parse(uni.getStorageSync("videoOssList"));
}
},
//子组件销毁前 //子组件销毁前
beforeDestroy() { beforeDestroy() {
this.handleEnd(); this.handleEnd();
@@ -132,7 +134,6 @@ export default {
// console.log("触发了更新"); // console.log("触发了更新");
}, },
methods: { methods: {
emitDispose1(status) { emitDispose1(status) {
this.$emit("handleSuccessDispose", status); this.$emit("handleSuccessDispose", status);
}, },
@@ -176,6 +177,15 @@ export default {
//播放结束 //播放结束
async handleEnd() { async handleEnd() {
// uni.showModal({
// title: "更新提示",
// content: "新版本已经准备好,是否重启应用?",
// success(res) {
// if (res.confirm) {
// }
// },
// });
this.setVideoTime(); this.setVideoTime();
}, },
//存播放进度 //存播放进度
@@ -416,11 +426,20 @@ export default {
initAliyunPlayer() { initAliyunPlayer() {
console.log("实例创建中 at line 436:", "实例创建中"); console.log("实例创建中 at line 436:", "实例创建中");
$("#url-player-test").empty(); $("#url-player-test").empty();
// const saveTime = function (memoryVideo,currentTime) {
// console.log(memoryVideo, currentTime)
// }
// const getTime = function (memoryVideo) {
// /* return返回的是自定义起播时间 */
// return 20
// }
var components = [ var components = [
{ {
name: "RateComponent", //倍速组件 name: "RateComponent", //倍速组件
type: AliPlayerComponent.RateComponent, type: AliPlayerComponent.RateComponent,
}, },
]; ];
if (this.platform != "ios") { if (this.platform != "ios") {
var fullScreenButtonComponent = Aliplayer.Component({ var fullScreenButtonComponent = Aliplayer.Component({
@@ -443,6 +462,8 @@ export default {
name: "adComponent", //自定义全屏组件 name: "adComponent", //自定义全屏组件
type: fullScreenButtonComponent, type: fullScreenButtonComponent,
}, },
]; ];
} }
@@ -477,9 +498,17 @@ export default {
if (this.platform == "ios") { if (this.platform == "ios") {
this.player.one("canplay", () => { this.player.one("canplay", () => {
this.player.seek(this.firstTime); this.player.seek(this.firstTime);
// uni.showToast({
// title: '已为您定位至上次观看位置'
// })
}); });
} else { } else {
this.player.seek(this.firstTime); this.player.seek(this.firstTime);
// uni.showToast({
// title: '已为您定位至上次观看位置'
// })
} }
this.player.one("timeupdate", () => { this.player.one("timeupdate", () => {
@@ -527,6 +556,7 @@ export default {
}, },
//调用 handleEnd 存储视频播放信息 //调用 handleEnd 存储视频播放信息
endEmitData(event, ownerInstance) { endEmitData(event, ownerInstance) {
ownerInstance.callMethod("handleEnd"); ownerInstance.callMethod("handleEnd");
}, },

View File

@@ -0,0 +1,413 @@
<template>
<view
class="container playerBox"
id="playerBox"
style="
background-color: #fff;
width: 100%;
height: 200px;
padding: 20rpx;
box-sizing: border-box;
position: relative;
"
>
<cx-audio :list="list" ref="cxaudio" :autoplays="true" @curTime="recordTime" :firstTime="firstTime">
<template slot="title" slot-scope="slotProps">
<view style="color: #fff; text-align: center;font-size: 36rpx;"
>{{ curriculumData.title }}
</view>
<view style="color: #fff; text-align: center;font-size: 28rpx;margin-top: 10px;"
>音频
{{ Number(currentVideoIndex+1)>10? Number(currentVideoIndex+1):'0'+ Number(currentVideoIndex+1) }}
</view>
</template>
</cx-audio>
</view>
</template>
<script>
import cxAudio from "./cx-audio-play.vue";
import store from "@/store/index.js";
import $http from "@/config/requestConfig.js";
import { mapState, mapMutations } from "vuex";
export default {
components: {
cxAudio,
},
props: {
videoData: {
type: Object,
default: {},
},
curriculumData: {
type: Object,
default: {},
},
videoInfo: {
type: Object,
default: {},
},
firstTime: {
type: Number,
default: 0,
},
currentVideoIndex: {
type: Number,
default: 0,
},
},
data() {
return {
list: [],
show: false, //视频提示显示
isDipose: false, //视频提示显示
content: "此设备暂不支持观看当前视频,请移步到安卓手机进行学习!",
platform: null, //设备类型
isFullScreen: false, //当前是否是全屏模式
isOnLoad: false, //是否刷新
isChange: false, //是否切换播放源
videoList: [], //视频列表
videoOssList: [], //本地视频列表
options: {}, //父组件传参
currentTime: "", //当前播放时间
isSetFirstTime: false, //是否获取到初始播放时间
urlList: {
checkVideo: "sociology/course/checkVideo",
},
};
},
computed: {
// ...mapState(["videoOssList"]),
},
watch: {
timer(newValue) {
this.$emit("child-event", newValue);
},
videoOssList: {
immediate: true,
handler(newValue) {
if (this.videoOssList.length > 0) {
uni.setStorageSync("videoOssList", JSON.stringify(this.videoOssList));
}
},
},
},
//
created() {
this.platform = this.$platform;
this.show = false;
if (uni.getStorageSync("videoOssList")) {
this.videoOssList = JSON.parse(uni.getStorageSync("videoOssList"));
}
this.list=[this.videoData.source]
},
mounted(){
this.init();
},
//子组件销毁前
beforeDestroy() {
this.handleEnd();
clearInterval(this.$store.state.videoTimer);
plus.screen.lockOrientation("portrait-primary");
},
updated() {
// console.log("触发了更新");
},
methods: {
init() {
console.log("at line 101:", "初始化");
console.log('this.list.push at line 127:', this.list)
this.$nextTick(() => {
this.$refs.cxaudio.init();
});
},
emitDispose1(status) {
this.$emit("handleSuccessDispose", status);
},
destory() {
// this.isDipose = true;
},
//ios不能播放私有加密提示信息
openShow() {
this.show = true;
},
changeVideoData() {
this.show = false;
this.isChange = false;
},
screenChange(data) {
this.isFullScreen = !data.status;
this.$emit("changeScreen", this.isFullScreen);
},
calcTimer(time){
console.log('time at line 111111111111111151:', time)
},
//当前播放时间 存本地
recordTime(time) {
this.currentTime = time;
var list = [...this.videoOssList];
var index = list.findIndex((e) => e.id == this.currentVideoId);
var setData = {
id: this.currentVideoId,
vid: this.videoData.vid,
time: time,
};
if (list.length > 0 && index >= 0) {
list[index] = setData;
} else {
list.push(setData);
}
this.videoOssList = list;
if (this.currentTime % 60 == 0) {
this.setVideoTime();
}
},
//播放结束
async handleEnd() {
this.setVideoTime();
},
//存播放进度
setVideoTime() {
console.log('存播放进度',this.currentTime)
if (!this.videoData.id) {
return false;
}
var data = {
videoId: this.videoData.id,
position: this.currentTime ? this.currentTime : 0, //秒数
loadAnimate: "none",
};
$http
.request({
url: `sociology/course/saveCoursePosition`,
method: "Post",
data,
header: {
"Content-Type": "application/json",
},
})
.then((res) => {});
},
//定时器 存播放进度
async setVideoFirtsetTime() {
this.setVideoTime();
},
},
};
</script>
<style>
.container {
width: 100vw;
height: auto;
/deep/.pause {
width: 60rpx !important;
height: 60rpx !important;
}
}
.fds {
background-color: blue;
height: 600rpx;
position: fixed;
top: 60rpx;
}
.returnBack {
flex-direction: row;
justify-content: flex-start;
align-items: center;
height: 88rpx;
padding-left: 20rpx;
}
.txt {
color: #fff;
}
.right_title {
background: #000;
height: 96rpx;
justify-content: space-between;
flex-direction: row;
align-items: center;
margin-left: auto;
}
.return {
flex-direction: row;
align-items: center;
color: #fff;
}
.right_handle {
width: 200rpx;
flex-direction: row;
justify-content: flex-end;
padding-right: 20rpx;
}
cover-view {
display: block;
line-height: 1.2;
overflow: hidden;
white-space: nowrap;
pointer-events: auto;
}
cover-view {
visibility: visible !important;
}
cover-image {
visibility: visible !important;
}
.fullScreenButton-container {
color: #fff;
float: right;
height: 35px;
margin-top: 6px;
margin-right: 5px;
display: flex;
align-items: center;
position: relative;
i {
color: #fff;
display: inline-block;
font-size: 22px;
display: block;
margin-top: 7px;
cursor: pointer;
& + i {
margin-left: 3px;
}
@media (min-width: 768px) {
&:hover + .player-tooltip {
display: block;
}
}
}
.player-tooltip {
&.prev {
left: -10px;
}
&.list {
left: 5px;
}
&.next {
right: -12px;
}
}
}
.playlist-content {
position: absolute;
right: 0;
width: 0px;
padding-bottom: 48px;
box-sizing: border-box;
height: 100%;
transition: all 0.38s ease-in-out;
overflow: hidden;
.list {
background-color: #000;
background-color: rgba(0, 0, 0, 0.3);
height: 100%;
overflow: auto;
.video-item {
color: #fff;
padding: 0px 10px;
line-height: 35px;
font-size: 14px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
&.active {
background-color: #000;
color: #00ddff;
}
@media (min-width: 768px) {
&:hover {
background-color: #000;
color: #00ddff;
}
}
}
}
}
.player-tooltip {
position: absolute;
display: none;
font-size: 12px;
color: #fff;
line-height: 28px;
letter-spacing: 0;
text-align: center;
background: #3c3c3c;
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.1);
height: 28px;
top: -48px;
padding: 0 5px;
white-space: nowrap;
}
.playlist-skip-tip {
padding: 5px 15px;
position: absolute;
top: 50%;
left: 50%;
z-index: 30;
line-height: 30px;
font-size: 14px;
border-radius: 4px;
background: rgba(255, 255, 255, 0.8);
color: #000;
text-align: center;
transform: translate(-50%, -50%);
}
#rotating-div {
width: 100vw;
height: 100vh;
background-color: #3498db;
transform: rotate(90deg);
/* 旋转90度 */
transform-origin: center center;
/* 设置旋转中心点在div中心 */
position: fixed;
/* 固定定位,全屏显示 */
left: 0;
top: 0;
bottom: 0;
right: 0;
}
.playerBox {
}
</style>

View File

@@ -0,0 +1,620 @@
<template>
<!--音频组件-->
<view
class="boxShadow"
style="
width: 100%;
border-radius: 40rpx;
height: 100%;
padding: 40rpx 0;
box-sizing: border-box;
background-image: linear-gradient(80deg, #959698 0%, #808183 100%);
"
>
<view class="bgfff">
<view>
<slot name="title"></slot>
<view class="audo-video">
<view class="slider-box">
<text class="mm">{{ timer }}</text>
<slider
style="width: calc(100% - 280rpx)"
@change="sliderChange"
@changing="sliderChanging"
class="audio-slider"
block-size="16"
:min="0"
:max="duration"
:value="currentTime"
activeColor="#FF8849"
@touchstart="lock = true"
@touchend="lock = false"
/>
<text class="ss" v-if="overTimer != 'NaN:NaN'">{{
overTimer
}}</text>
<text class="ss" v-else>00.00</text>
</view>
<!--音频播放按钮处-->
<view class="audo-top">
<!--上一首-->
<!-- <image
src="./icon/xys.png"
style="width: 40rpx; height: 40rpx; transform: rotate(180deg)"
mode="aspectFill"
@click="upper(1)"
></image> -->
<!--上一首-->
<!--快退-->
<image
src="./icon/kt.png"
style="width: 40rpx; height: 40rpx"
mode="widthFix"
@click="jump('kt')"
></image>
<!--快退-->
<!--播放-->
<image
src="./icon/kt.png"
style="width: 100rpx; height: 100rpx"
mode="widthFix"
@click="plays()"
></image>
<!--播放-->
<!--快进-->
<image
src="./icon/kj.png"
style="width: 40rpx; height: 40rpx"
mode="widthFix"
@click="jump('kj')"
></image>
<!--快进-->
<!--下一首-->
<!-- <image
src="./icon/xys.png"
style="width: 40rpx; height: 40rpx"
mode="aspectFill"
@click="upper(2)"
></image> -->
<!--下一首-->
<view class="audo-a" style="">
<!--进度条-->
<!--进度条-->
<!--倍数-->
<view
class="beishu"
style="border: 1rpx solid #e1dbf2"
@click="beishu"
>{{ BsNav[bsindex].bs }} X
</view>
<view class="absolute" style="right: 0; top: 80rpx" v-if="shows">
<!-- <u-transition :show="show" mode="slide-right" duration="300"> -->
<view
class="beishu-a"
style="border: 1rpx solid #fff"
v-if="show"
>
<view
v-for="(item, index) in BsNav"
:key="index"
@click="setRate(index, item)"
class="title beishuItem"
:style="{ color: bsid == item.id ? '#9461EB' : '' }"
>
{{ item.bs }} X
</view>
</view>
<!-- </u-transition> -->
</view>
<!--倍数-->
</view>
</view>
<!--音频播放按钮处-->
<!--音频api处[视频代替音频-实现倍数功能]-->
<video
id="myVideo"
ref="myVideo"
:src="recorPath"
class="hidden"
@timeupdate="timeupdate"
:autoplay="autoplays"
@loadedmetadata="loadedmetadata"
@ended="next"
controls
style="width: 10rpx; height: 10rpx"
></video>
<!--音频api处[视频代替音频-实现倍数功能]-->
</view>
</view>
</view>
<!--占位-->
</view>
<!--音频组件 wx:cxalq8-24 Author:chenxin-->
</template>
<script>
/*
list -- 音频数据: 数组格式/不传无法播放
Seconds -- 快进快退秒数: 默认15秒
autoNext -- 是否自动播放下一首
autoplays -- 进入页面是否自动播放 - 默认false
slideYes -- 滑动进度条时是否开启播放 - 默认false
switAud -- 切换上下音频是否开启播放 - 默认true
BsNav -- 倍数数据传入/数组形式
图片功能样式,如想改动请在组件内部修改,页面中已注释 -- 逻辑根据自己需求改
目前只测试 微信小程序和H5和APP -- 其他平台未知
[Author:chenxin 交流vx:cxalq8-24]
*/
export default {
name: "cx-audio-play",
props: {
list: {
//音频数据
Type: Array,
default: () => [],
},
Seconds: {
//快进快退 - 秒数
Type: Number,
default: 15,
},
firstTime: {
//快进快退 - 秒数
Type: Number,
default: 0,
},
autoNext: {
//是否自动播放下一首
Type: Boolean,
default: false,
},
autoplays: {
//是否开启自动播放
Type: Boolean,
default: false,
},
slideYes: {
//滑动进度条 - 是否开启播放
Type: Boolean,
default: false,
},
switAud: {
Type: Boolean, //切换上下音频 - 是否开启播放
default: true,
},
BsNav: {
//倍数-传入
Type: Array,
default: () => [
{
id: 1.0,
bs: "1.0",
},
{
id: 1.5,
bs: "1.5",
},
{
id: 2.0,
bs: "2.0",
},
],
},
},
data() {
return {
shows: false, //倍数弹框
show: true, //倍数弹框动画默认开启
succes: false, //播放按钮
bsid: "", //倍数默认显示第一个
bsindex: 0, //倍数默认显示第一个
num: 0,
current: 0, //当前选中的索引
recorPath: "", //音频播放地址
lock: false, // 锁
currentTime: 0, //当前进度
duration: 100, // 总进度
videoContext: null,
loading: true, //锁 加载
curTime: null, //锁 加载
};
},
onReady() {},
onShow() {},
mounted() {
//初始化音频api
},
updated() {},
onLoad() {},
onHide() {
//监听页面离开 - 销毁音频
this.stop_();
this.$emit("curTime", this.curTime);
},
onUnload() {
//监听页面卸载 - 销毁音频
this.stop_();this.$emit("curTime", this.curTime);
},
destroyed() {
// this.innerAudioContext.stop();
},
computed: {
timer() {
this.curTime = this.currentTime;
return calcTimer(this.currentTime);
},
overTimer() {
this.curTime = this.duration;
return calcTimer(this.duration);
},
},
methods: {
init() {
this.currentTime=this.firstTime;
this.videoContext = uni.createVideoContext("myVideo", this);
//默认播放第一个
if (this.list.length != 0) {
this.recorPath = this.list[0];
if (this.autoplays) {
this.succes = true;
}
} else {
this.duration = 0;
}
//倍数默认选择第一个
if (this.BsNav.length != 0) {
this.bsid = this.BsNav[0].id;
this.playbackRate(); //倍数
}
this.seek(this.firstTime);
this.curTime = this.currentTime
},
//没有音频数据
noUrl() {
if (this.list.length == 0) {
uni.showToast({
title: "请先传入音频数据哦~",
icon: "none",
});
return false;
}
return true;
},
//播放暂停
plays() {
if (!this.noUrl()) {
return;
}
this.playLoading();
this.succes = !this.succes;
this.succes ? this.play_() : this.pause_();
},
//上下首切换
upper(num) {
if (!this.noUrl()) {
return;
}
let that = this;
if (num == 1) {
//上一首
if (this.num == 0) {
this.upperToast(num); //提示
return;
}
this.num -= 1;
} else {
//下一首
if (this.num + 1 == this.list.length) {
this.upperToast(num); //提示
return;
}
this.num += 1;
}
this.recorPath = this.list[this.num];
if (this.switAud) {
// 切换时是否开启播放
this.succes = true;
this.play_();
} else {
this.succes = false;
}
this.playbackRate(); //倍数
console.log("当前音频:", this.recorPath);
},
//快进快退
jump(e) {
if (!this.noUrl()) {
return;
}
var num;
if (e == "kt") {
num = (this.currentTime - Math.floor(this.Seconds % 60)).toFixed(0); //当前时间-15秒
} else {
num = (this.currentTime + Math.floor(this.Seconds % 60)).toFixed(0); //当前时间+15秒
}
this.seek(num);
},
seek(num) {
this.$nextTick(() => {
//#ifdef H5
this.$refs.myVideo.seek(num);
//#endif
//#ifndef H5
this.videoContext.seek(num);
//#endif
});
},
//倍速弹框
beishu() {
this.shows = !this.shows;
},
// 倍速
setRate(index, item) {
this.bsid = item.id;
this.bsindex = index;
this.shows = false;
this.playbackRate();
},
// 更新进度条
timeupdate(event) {
if (this.lock) return; // 锁
var currentTime, duration;
if (event.detail.detail) {
currentTime = event.detail.detail.currentTime;
duration = event.detail.detail.duration;
} else {
currentTime = event.detail.currentTime;
duration = event.detail.duration;
}
this.currentTime = currentTime;
this.duration = duration;
},
// 拖动进度条
sliderChange(data) {
if (!this.noUrl()) {
return;
}
//此处滑动进度条--开始播放
if (this.slideYes && !this.succes) {
this.play_();
this.succes = true;
}
//#ifdef H5
this.$refs.myVideo.seek(data.detail.value); //获取秒数
//#endif
//#ifndef H5
this.videoContext.seek(data.detail.value); //获取秒数
//#endif
},
//拖动中
sliderChanging(data) {
if (data.detail.value == 0) {
this.succes = false;
this.pause_();
}
this.currentTime = data.detail.value;
},
// 视频加载完成
loadedmetadata(data) {
this.duration = data.detail.duration;
},
//音频结束触发
next(data) {
this.succes = false;
if (this.autoNext) {
//自动播放下一首
this.upper(2);
}
},
// 各平台播放_暂停
play_() {
this.$nextTick(() => {
//#ifdef H5
this.$refs.myVideo.play();
//#endif
//#ifndef H5
this.videoContext.play();
//#endif
});
},
pause_() {
this.$nextTick(() => {
//#ifdef H5
this.$refs.myVideo.pause();
//#endif
//#ifndef H5
this.videoContext.pause();
//#endif
});
},
//离开页面暂停播放
stop_() {
this.$nextTick(() => {
//#ifdef H5
this.$refs.myVideo.stop();
//#endif
//#ifndef H5
this.videoContext.stop();
//#endif
});
},
//提示
upperToast(num) {
num == 1
? uni.showToast({
title: "到头了~",
icon: "none",
})
: uni.showToast({
title: "没有更多了~",
icon: "none",
});
},
//音频倍数
playbackRate() {
this.$nextTick(() => {
//#ifdef H5
this.$refs.myVideo.playbackRate(this.bsid);
//#endif
//#ifndef H5
this.videoContext.playbackRate(this.bsid);
//#endif
});
},
//加载框--封
playLoading() {
if (this.loading && !this.succes) {
uni.showLoading({
title: "音频加载中...",
});
this.loading = false;
}
setTimeout(() => {
uni.hideLoading();
}, 1500);
},
},
watch: {
//播放器当前播放进度
curTime(val) {
if (this.curTime !== null) {
console.log("timer at line 495:", this.curTime);
this.$emit("curTime", this.curTime);
}
},
},
};
//时间换算
function calcTimer(timer) {
console.log('timer at line 514:', timer)
if (timer === 0 || typeof timer !== "number") {
return "00:00";
}
let mm = Math.floor(timer / 60);
let ss = Math.floor(timer % 60);
if (mm < 10) {
mm = "0" + mm;
}
if (ss < 10) {
ss = "0" + ss;
}
return mm + ":" + ss;
}
</script>
<style lang="scss" scoped>
page {
background-color: #f8f8f8;
}
/* #video {
width: 100%;
} */
.audo-video {
margin-top: 0rpx;
color: #fff;
.beishuItem {
color: #999;
}
}
.slider-box {
display: flex;
align-items: center;
justify-content: center;
font-size: 27rpx;
// color: #fff;
}
button {
display: inline-block;
width: 100rpx;
background-color: #fff;
font-size: 24rpx;
color: #000;
padding: 0;
}
.hidden {
position: fixed;
top: 0;
left: -10rpx;
z-index: -1;
width: 1rpx;
height: 1rpx;
}
.audo-top {
padding: 20rpx 0;
display: flex;
justify-content: space-around;
align-items: center;
image {
width: 45rpx;
height: 45rpx;
}
}
.audo-a {
display: flex;
justify-content: space-between;
align-items: center;
width: auto;
position: relative;
z-index: 9;
margin-right: -20rpx;
}
.beishu {
position: relative;
width: 100rpx;
padding-top: 5rpx;
padding-bottom: 5rpx;
text-align: center;
border-radius: 25rpx;
font-size: 28rpx;
}
.absolute {
position: absolute;
.beishu-a {
width: 200rpx;
border-radius: 20rpx;
text-align: center;
line-height: 90rpx;
background: #fff;
.title {
pdding-left: 30rpx;
}
}
}
</style>

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@@ -29,16 +29,32 @@
此设备暂不支持观看当前视频<br />请移步到安卓手机进行学习 此设备暂不支持观看当前视频<br />请移步到安卓手机进行学习
</view> </view>
<view v-else> <view v-else>
<common-list-aliyun <template v-if="showAliYunPlayer">
id="AliPlayer" <common-list-audio
:showAliYunPlayer="showAliYunPlayer" id="commonAudio"
@handleSuccessDispose="handleSuccessDispose" :showAliYunPlayer="showAliYunPlayer"
ref="commonVideoAliyun" @handleSuccessDispose="handleSuccessDispose"
v-if="showAliYunPlayer" ref="commonVideoAliyun1"
:videoData="videoData" v-if="videoInfo.type == 2"
:firstTime="firstTime" :videoData="videoData"
> :currentVideoIndex="currentVideoIndex"
</common-list-aliyun> :videoInfo="videoInfo"
:curriculumData="curriculumData"
:firstTime="firstTime"
>
</common-list-audio>
<common-list-aliyun
id="AliPlayer"
:showAliYunPlayer="showAliYunPlayer"
@handleSuccessDispose="handleSuccessDispose"
ref="commonVideoAliyun"
v-if="videoInfo.type != 2"
:videoData="videoData"
:firstTime="firstTime"
>
</common-list-aliyun>
</template>
<view v-else style="height: 200px"> </view> <view v-else style="height: 200px"> </view>
</view> </view>
</view> </view>
@@ -54,6 +70,18 @@ export default {
type: Number, type: Number,
default: null, default: null,
}, },
currentVideoIndex: {
type: Number,
default: null,
},
curriculumData: {
type: Object,
default: {},
},
secondCountDown: {
type: Number,
default: null,
},
isfresh: { isfresh: {
type: Boolean, type: Boolean,
default: false, default: false,
@@ -61,6 +89,8 @@ export default {
}, },
data() { data() {
return { return {
showCountDown: false,
playEndBlank: false,
flag: false, //视频提示显示 flag: false, //视频提示显示
show: false, //视频提示显示 show: false, //视频提示显示
// isfresh: false, //视频提示显示 // isfresh: false, //视频提示显示
@@ -75,6 +105,7 @@ export default {
options: {}, //父组件传参 options: {}, //父组件传参
currentTime: "", //当前播放时间 currentTime: "", //当前播放时间
videoData: {}, //获取当前的播放信息playAuthm3u8url videoData: {}, //获取当前的播放信息playAuthm3u8url
videoInfo: {}, //获取当前的播放信息playAuthm3u8url
isSetFirstTime: false, //是否获取到初始播放时间 isSetFirstTime: false, //是否获取到初始播放时间
firstTime: 0, //初始播放时间 firstTime: 0, //初始播放时间
@@ -136,6 +167,11 @@ export default {
}, },
beforeUpdate() {}, beforeUpdate() {},
methods: { methods: {
hideNextVideo() {
this.showCountDown = false;
this.playEndBlank = false;
this.$emit("hideNextVideo");
},
destory() { destory() {
if (this.showAliYunPlayer) { if (this.showAliYunPlayer) {
this.$nextTick(() => { this.$nextTick(() => {
@@ -182,10 +218,13 @@ export default {
}, },
}) })
.then(async (res) => { .then(async (res) => {
console.log("res at line 204:", res.video);
var that = this; var that = this;
this.videoInfo=res.video
that.videoData = { that.videoData = {
id: that.currentVideoId, id: that.currentVideoId,
vid: res.video.video, vid: res.video.video,
}; };
if (res.video.type == 1) { if (res.video.type == 1) {
@@ -225,7 +264,9 @@ export default {
that.firstTime = list[index].time ? list[index].time : 0; that.firstTime = list[index].time ? list[index].time : 0;
} }
} }
if (res.video.duration - that.firstTime <= 2) {
that.firstTime = 0;
}
that.videoOssList = [...list]; that.videoOssList = [...list];
} }
@@ -238,6 +279,7 @@ export default {
<script module="renderScript" lang="renderjs"> <script module="renderScript" lang="renderjs">
import $ from "jquery"; import $ from "jquery";
export default { export default {
data() { data() {
return { return {
@@ -322,4 +364,24 @@ export default {
height: 60rpx !important; height: 60rpx !important;
} }
} }
.showCountDownd {
box-sizing: border-box;
height: 100%;
width: 100%;
background-color: rgba(0, 0, 0, 0.6);
display: flex;
align-items: center;
justify-content: flex-end;
color: #fff;
font-size: 38rpx;
text-align: center;
position: absolute;
top: 0;
right: 10rpx;
z-index: 4;
text {
}
}
</style> </style>

View File

@@ -374,6 +374,7 @@ export default {
this.timer = null; this.timer = null;
await this.setVideoTime(); await this.setVideoTime();
}, },
setVideoTime(time) { setVideoTime(time) {
var data = {}; var data = {};

View File

@@ -18,11 +18,14 @@
<common-video <common-video
:isfresh="isfresh" :isfresh="isfresh"
v-if="isfresh" v-if="isfresh"
:secondCountDown="secondCountDown"
@handleFresh="handleFresh" @handleFresh="handleFresh"
@changeScreen="changeScreen" @changeScreen="changeScreen"
@changeScreenLoading="changeScreenLoading" @changeScreenLoading="changeScreenLoading"
ref="commonVideo" ref="commonVideo"
:currentVideoId="currentVideoId" :currentVideoId="currentVideoId"
:currentVideoIndex="currentVideoIndex"
:curriculumData="curriculumData"
> >
</common-video> </common-video>
<view style="color: #fff"></view> <view style="color: #fff"></view>
@@ -246,6 +249,7 @@ export default {
}, },
data() { data() {
return { return {
secondCountDown: 10,
isFullScreen: false, isFullScreen: false,
screenLoading: false, screenLoading: false,
isfresh: false, isfresh: false,
@@ -315,6 +319,7 @@ export default {
curriculumInfo: "app/phone.do?getCourseInfo", curriculumInfo: "app/phone.do?getCourseInfo",
}, },
currentVideoId: null, currentVideoId: null,
currentVideoIndex: null,
currentSelectVideoId: null, currentSelectVideoId: null,
currentSelectVideo: {}, currentSelectVideo: {},
}; };
@@ -331,6 +336,14 @@ export default {
computed: { computed: {
...mapState(["userInfo"]), ...mapState(["userInfo"]),
}, },
watch: {
currentVideoId() {
this.currentVideoIndex = this.videoArray.findIndex(
(e) => e.id == this.currentVideoId
); console.log('that.currentVideoIndex at line 3401111111111111:', this.currentVideoIndex)
},
},
methods: { methods: {
changeScreenLoading(status) { changeScreenLoading(status) {
this.screenLoading = status; this.screenLoading = status;
@@ -355,9 +368,9 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
// this.$refs.commonVideo.destory(); // this.$refs.commonVideo.destory();
// if (data.id != this.currentVideoId) { // if (data.id != this.currentVideoId) {
this.currentVideo = data; this.currentVideo = data;
this.currentVideoId = data.id; this.currentVideoId = data.id;
this.isfresh = true; this.isfresh = true;
// } // }
}); });
@@ -411,10 +424,10 @@ export default {
.then(async (res) => { .then(async (res) => {
that.curriculumData = res.data.detail; that.curriculumData = res.data.detail;
that.videoArray = res.data.videos; that.videoArray = res.data.videos;
if (that.videoArray.length > 0) {that.currentVideo = that.videoArray[0]; if (that.videoArray.length > 0) {
that.currentVideo = that.videoArray[0];
that.currentVideoId = that.videoArray[0].id; that.currentVideoId = that.videoArray[0].id;
that.isfresh = true; that.isfresh = true;
} }
}); });

View File

@@ -0,0 +1,16 @@
## 2.0.12023-12-15
优化体积和倍数播放功能
## 2.0.02023-12-15
修改一些bug兼容基本平台
## 1.0.72023-12-15
优化功能体积速度
## 1.0.52023-12-15
优化功能,兼容基本平台
## 1.0.42023-12-15
简化代码优化功能处理一些bug
## 1.0.32023-02-09
修改切换的某些bug新增自动播放下一首功能
## 1.0.22022-12-16
适配app平台
## 1.0.12022-12-16
1.0.1

View File

@@ -0,0 +1,576 @@
<template>
<!--音频组件-->
<view>
<view class="bgfff">
<view>
<view class="audo-video">
<!--音频播放按钮处-->
<view class="audo-top">
<!--上一首切换按钮-->
<image v-if="jian" style="width:50rpx;height:50rpx;" @click="nosig" src="/static/sys.png" mode="aspectFill"></image>
<image v-else @click="sig" src="/static/xys.png" style="width:50rpx;height:50rpx;transform:rotate(180deg)"
mode="aspectFill"></image>
<!--上一首切换按钮-->
<!--快退按钮-->
<image src="/static/kt.png" style="width:45rpx;height:45rpx;" mode="aspectFill" @click="kt()"></image>
<!--快退按钮-->
<!--播放按钮-->
<image :src="succes?'/static/bofang2.png':'/static/zt.png'" mode="aspectFill"
style="width:180rpx;height:180rpx;" @click="plays()"></image>
<!--播放按钮-->
<!--快进按钮-->
<image src="/static/kj.png" style="width:45rpx;height:45rpx;" mode="aspectFill" @click="kj()"></image>
<!--快进按钮-->
<!--下一首切换按钮-->
<image v-if="jia" @click="noxig" style="width:50rpx;height:50rpx;transform:rotate(180deg)" src="/static/sys.png"
mode="aspectFill"> </image>
<image v-else style="width:50rpx;height:50rpx;" src="/static/xys.png" @click="xig" mode="aspectFill"></image>
<!--下一首切换按钮-->
</view>
<!--音频播放按钮处-->
<!--音频api处[视频代替音频-实现倍数功能]-->
<video id="myVideo" ref="myVideo" :src="recorPath" class="hidden" @timeupdate="timeupdate"
:autoplay="autoplays" @loadedmetadata="loadedmetadata" @ended="next" controls
style="width: 10rpx;height:10rpx;">
</video>
<!--音频api处[视频代替音频-实现倍数功能]-->
<view class="audo-a" style="margin:0 auto;">
<!--进度条-->
<view class="slider-box">
<text class="mm">{{timer}}</text>
<slider style="width: 370rpx;" @change="sliderChange" @changing="sliderChanging"
class="audio-slider" block-size="16" :min="0" :max="duration" :value="currentTime"
activeColor="#FFA929" @touchstart="lock= true" @touchend="lock = false" />
<text class="ss" v-if="overTimer!='NaN:NaN'">{{overTimer}}</text>
<text class="ss" v-else>00.00</text>
</view>
<!--进度条-->
<!--倍数-->
<view class="beishu" style="border:3rpx solid #C8C9CC;" @click="beishu">{{BsNav[bsindex].bs}} X
</view>
<view class="absolute" style="right:0;top:80rpx;" v-if="shows">
<!-- <u-transition :show="show" mode="slide-right" duration="300"> -->
<view class="beishu-a" style="border:2rpx solid #C8C9CC;" v-if="show">
<view v-for="(item,index) in BsNav" :key="index" @click="setRate(index,item)"
class="title" :style="{color:bsid==item.id?'#8D48FE':''}">
{{item.bs}} X
</view>
</view>
<!-- </u-transition> -->
</view>
<!--倍数-->
</view>
</view>
</view>
</view>
<view class="h-100"></view>
<!--占位-->
</view>
<!--音频组件 Author:chenxin-->
</template>
<script>
/*
list -- 音频文件传入 不传无法播放/数组形式
Faskms -- 快进秒数 number 默认15秒
Slowms -- 快退秒数 number 默认15秒
autoNext -- 是否自动播放下一首
autoplays -- 进入页面是否自动播放 - 默认false
slideYes -- 滑动进度条时是否开启播放 - 默认false
switAud -- 切换上下音频是否开启播放 - 默认false
BsNav -- 倍数数据传入/数组形式
按钮图片未自定义,如想改动请在组件内部修改,页面头部已注释 -- 逻辑根据自己需求改
目前只测试 微信小程序和H5和APP -- 其他平台未知
Author:chenxin 交流vx:cxalq8-24
*/
export default {
name: "cx-audio-play",
props: {
list: { //音频数据
Type: Array,
default: () => []
},
Faskms: { //快进秒数
Type: Number,
default: 15,
},
Slowms: { //快退秒数
Type: Number,
default: 15,
},
autoNext: {
Type: Boolean,
default: false,
},
autoplays: { //是否开启自动播放
Type: Boolean,
default: false,
},
slideYes: { //滑动进度条 - 是否开启播放
Type: Boolean,
default: false,
},
switAud: {
Type: Boolean, //切换上下音频 - 是否开启播放
default: false,
},
BsNav: { //倍数-传入
Type: Array,
default: () => [{
id: 1.0,
bs: '1.0',
}, {
id: 1.5,
bs: '1.5'
}, {
id: 2.0,
bs: '2.0'
}],
},
},
data() {
return {
shows: false, //倍数弹框
show: true, //倍数弹框动画默认开启
jian: true, //减-切换图标
jia: true, //加-切换图标
succes: false, //播放按钮
bsid: '', //倍数默认显示第一个
bsindex: 0, //倍数默认显示第一个
num: 0,
current: 0, //当前选中的索引
recorPath: '', //音频播放地址
lock: false, // 锁
currentTime: 0, //当前进度
duration: 100, // 总进度
videoContext: null,
loading: true, //锁 加载
}
},
onReady() {},
onShow() {},
mounted() {
this.videoContext = uni.createVideoContext('myVideo', this)
//默认播放第一个 -- 按钮展示
if (this.list.length != 0) {
this.recorPath = this.list[0].recorPath
if (this.list.length > 1) { //音频文件大于1 -- 下一个切换默认显示
this.jia = false
if (this.autoplays) {
this.succes = true
}
}
}
//倍数默认处理
if (this.BsNav.length != 0) {
this.bsid = this.BsNav[0].id
this.$nextTick(() => {
//#ifdef H5
this.$refs.myVideo.playbackRate(this.bsid)
//#endif
//#ifndef H5
this.videoContext.playbackRate(this.bsid)
//#endif
})
}
},
updated() {
},
onLoad() {
},
onHide() { //监听页面离开 - 销毁音频
//#ifdef H5
this.$refs.myVideo.stop();
//#endif
//#ifndef H5
this.videoContext.stop();
//#endif
},
onUnload() { //监听页面卸载 - 销毁音频
//#ifdef H5
this.$refs.myVideo.stop();
//#endif
//#ifndef H5
this.videoContext.stop();
//#endif
},
destroyed() {
// this.innerAudioContext.stop();
},
computed: {
timer() {
return calcTimer(this.currentTime)
},
overTimer() {
return calcTimer(this.duration)
}
},
watch: {
},
methods: {
plays() { //播放暂停
if (!this.list || this.list.length == 0) {
console.log('暂无音频数据~')
return;
}
this.playloading()
this.succes = !this.succes
if (this.succes) {
// this.currentTime = 0
// console.log('-----------------')
//#ifdef H5
this.$refs.myVideo.play()
//#endif
//#ifndef H5
this.videoContext.play()
//#endif
} else {
uni.hideLoading()
//#ifdef H5
this.$refs.myVideo.pause()
//#endif
//#ifndef H5
this.videoContext.pause()
//#endif
}
},
beishu() { //倍速弹框
this.shows = !this.shows
},
// 倍速
setRate(index, item) {
this.bsid = item.id
this.bsindex = index
this.shows = false
//#ifdef H5
this.$refs.myVideo.playbackRate(item.id)
//#endif
//#ifndef H5
this.videoContext.playbackRate(item.id)
//#endif
},
// 更新进度条
timeupdate(event) {
if (this.lock) return; // 锁
var currentTime, duration;
if (event.detail.detail) {
currentTime = event.detail.detail.currentTime
duration = event.detail.detail.duration
} else {
currentTime = event.detail.currentTime
duration = event.detail.duration
}
this.currentTime = currentTime
this.duration = duration
},
// 拖动进度条
sliderChange(data) {
//此处滑动进度条--开始播放
if (this.slideYes && !this.succes) {
//#ifdef H5
this.$refs.myVideo.play()
//#endif
//#ifndef H5
this.videoContext.play()
//#endif
this.succes = true
}
//#ifdef H5
this.$refs.myVideo.seek(data.detail.value) //获取秒数
//#endif
//#ifndef H5
this.videoContext.seek(data.detail.value) //获取秒数
//#endif
},
//拖动中
sliderChanging(data) {
if (data.detail.value == 0) {
this.succes = false
//#ifdef H5
this.$refs.myVideo.pause()
//#endif
//#ifndef H5
this.videoContext.pause()
//#endif
}
this.currentTime = data.detail.value
},
// 视频加载完成
loadedmetadata(data) {
this.duration = data.detail.duration
},
sig() { //上一首
if (!this.list || this.list.length == 0) {
console.log('暂无音频数据~')
return;
}
this.num -= 1
if (this.num < this.list.length) {
this.loading = true
this.playloading() //加载框
}
if (this.num + 1 < this.list.length && this.num + 1 != 1) { //点击上一首小于音频数据总长度
this.jia = false // 下按钮-亮且可点击
this.jian = false // 上按钮-亮且可点击
} else {
this.jian = true // 上按钮-灰且阻止
this.jia = false // 下按钮-亮且可点击
}
this.recorPath = this.list[this.num].recorPath
if (this.switAud) { //切换时是否默认开启播放
this.succes = true
setTimeout(() => {
//#ifdef H5
this.$refs.myVideo.play()
//#endif
//#ifndef H5
this.videoContext.play()
//#endif
}, 100)
} else {
this.succes = false
}
},
xig() { //下一首
if (!this.list || this.list.length == 0) {
console.log('暂无音频数据~')
return;
}
this.num += 1
if (this.num < this.list.length) {
this.loading = true
this.playloading() //加载框
}
if (this.num + 1 < this.list.length) { //点击下一首小于音频数据总长度
this.jia = false // 下按钮-亮且可点击
this.jian = false // 上按钮-亮且可点击
} else { //大于总长度
this.jia = true //下按钮 - 灰且阻止
this.jian = false //上按钮 - 亮可点击
}
this.recorPath = this.list[this.num].recorPath
if (this.switAud) { //切换时是否默认开启播放
this.succes = true
setTimeout(() => {
//#ifdef H5
this.$refs.myVideo.play()
//#endif
//#ifndef H5
this.videoContext.play()
//#endif
}, 100)
} else {
this.succes = false
}
},
nosig() {
uni.showToast({
title: '到头了~',
icon: "none"
})
},
noxig() {
uni.showToast({
title: '没有更多了~',
icon: "none"
})
},
kt() { //快退
if (!this.list || this.list.length == 0) {
console.log('暂无音频数据~')
return;
}
let a = (this.currentTime - Math.floor(15 % 60)).toFixed(0) //当前时间-15秒
if (a < 1) {
this.succes = false
//#ifdef H5
this.$refs.myVideo.pause()
//#endif
//#ifndef H5
this.videoContext.pause()
//#endif
}
//#ifdef H5
this.$refs.myVideo.seek(a)
//#endif
//#ifndef H5
this.videoContext.seek(a)
//#endif
},
kj() { //快进
if (!this.list || this.list.length == 0) {
console.log('暂无音频数据~')
return;
}
let a = (this.currentTime + Math.floor(15 % 60)).toFixed(0) //当前时间+15秒
//#ifdef H5
this.$refs.myVideo.seek(a)
//#endif
//#ifndef H5
this.videoContext.seek(a)
//#endif
},
next(data) { //监听音频结束
this.succes = false
/*音频结束--是否自动播放下一首*/
if (!this.autoNext) {
return
}
if (this.num + 1 < this.list.length) {
this.succes = true
this.num += 1
this.recorPath = this.list[this.num].recorPath
setTimeout(() => {
//#ifdef H5
this.$refs.myVideo.play()
//#endif
//#ifndef H5
this.videoContext.play()
//#endif
}, 100)
} else {
this.jia = true //下按钮 - 灰且阻止
this.jian = false //上按钮 - 亮可点击
}
// console.log('音频结束-------')
},
playloading() { //加载框--封
if (this.loading) {
uni.showLoading({
title: "音频缓存中..."
})
this.loading = false
}
setTimeout(() => {
uni.hideLoading()
}, 1600)
},
},
watch: {}
}
//时间换算
function calcTimer(timer) {
if (timer === 0 || typeof timer !== 'number') {
return '00:00'
}
let mm = Math.floor(timer / 60)
let ss = Math.floor(timer % 60)
if (mm < 10) {
mm = '0' + mm
}
if (ss < 10) {
ss = '0' + ss
}
return mm + ':' + ss
}
</script>
<style lang="scss" scoped>
page {
background-color: #F6F6F8;
}
/* #video {
width: 100%;
} */
.audo-video {
padding-bottom: 20rpx;
color: #999;
}
.slider-box {
display: flex;
align-items: center;
justify-content: center;
font-size: 27rpx;
color: #999;
}
button {
display: inline-block;
width: 100rpx;
background-color: #fff;
font-size: 24rpx;
color: #000;
padding: 0;
}
.hidden {
position: fixed;
top: 0;
left: -10rpx;
z-index: -1;
width: 1rpx;
height: 1rpx;
}
.audo-top {
padding: 20rpx 40rpx;
display: flex;
justify-content: space-around;
align-items: center;
image {
width: 45rpx;
height: 45rpx;
}
}
.audo-a {
display: flex;
justify-content: space-between;
align-items: center;
width: 700rpx;
position: relative;
z-index: 9;
}
.beishu {
position: relative;
width: 100rpx;
padding-top: 5rpx;
padding-bottom: 5rpx;
text-align: center;
border-radius: 25rpx;
font-size: 28rpx;
}
.absolute {
position: absolute;
.beishu-a {
width: 200rpx;
border-radius: 20rpx;
text-align: center;
line-height: 90rpx;
background: #fff;
.title {
pdding-left: 30rpx;
}
}
}
</style>

View File

@@ -0,0 +1,576 @@
<template>
<!--音频组件-->
<view>
<view class="bgfff">
<view>
<view class="audo-video">
<!--音频播放按钮处-->
<view class="audo-top">
<!--上一首切换按钮-->
<image v-if="jian" style="width:50rpx;height:50rpx;" @click="nosig" src="/static/sys.png" mode="aspectFill"></image>
<image v-else @click="sig" src="/static/xys.png" style="width:50rpx;height:50rpx;transform:rotate(180deg)"
mode="aspectFill"></image>
<!--上一首切换按钮-->
<!--快退按钮-->
<image src="/static/kt.png" style="width:45rpx;height:45rpx;" mode="aspectFill" @click="kt()"></image>
<!--快退按钮-->
<!--播放按钮-->
<image :src="succes?'/static/bofang2.png':'/static/zt.png'" mode="aspectFill"
style="width:180rpx;height:180rpx;" @click="plays()"></image>
<!--播放按钮-->
<!--快进按钮-->
<image src="/static/kj.png" style="width:45rpx;height:45rpx;" mode="aspectFill" @click="kj()"></image>
<!--快进按钮-->
<!--下一首切换按钮-->
<image v-if="jia" @click="noxig" style="width:50rpx;height:50rpx;transform:rotate(180deg)" src="/static/sys.png"
mode="aspectFill"> </image>
<image v-else style="width:50rpx;height:50rpx;" src="/static/xys.png" @click="xig" mode="aspectFill"></image>
<!--下一首切换按钮-->
</view>
<!--音频播放按钮处-->
<!--音频api处[视频代替音频-实现倍数功能]-->
<video id="myVideo" ref="myVideo" :src="recorPath" class="hidden" @timeupdate="timeupdate"
:autoplay="autoplays" @loadedmetadata="loadedmetadata" @ended="next" controls
style="width: 10rpx;height:10rpx;">
</video>
<!--音频api处[视频代替音频-实现倍数功能]-->
<view class="audo-a" style="margin:0 auto;">
<!--进度条-->
<view class="slider-box">
<text class="mm">{{timer}}</text>
<slider style="width: 370rpx;" @change="sliderChange" @changing="sliderChanging"
class="audio-slider" block-size="16" :min="0" :max="duration" :value="currentTime"
activeColor="#FFA929" @touchstart="lock= true" @touchend="lock = false" />
<text class="ss" v-if="overTimer!='NaN:NaN'">{{overTimer}}</text>
<text class="ss" v-else>00.00</text>
</view>
<!--进度条-->
<!--倍数-->
<view class="beishu" style="border:3rpx solid #C8C9CC;" @click="beishu">{{BsNav[bsindex].bs}} X
</view>
<view class="absolute" style="right:0;top:80rpx;" v-if="shows">
<!-- <u-transition :show="show" mode="slide-right" duration="300"> -->
<view class="beishu-a" style="border:2rpx solid #C8C9CC;" v-if="show">
<view v-for="(item,index) in BsNav" :key="index" @click="setRate(index,item)"
class="title" :style="{color:bsid==item.id?'#8D48FE':''}">
{{item.bs}} X
</view>
</view>
<!-- </u-transition> -->
</view>
<!--倍数-->
</view>
</view>
</view>
</view>
<view class="h-100"></view>
<!--占位-->
</view>
<!--音频组件 Author:chenxin-->
</template>
<script>
/*
list -- 音频文件传入 不传无法播放/数组形式
Faskms -- 快进秒数 number 默认15秒
Slowms -- 快退秒数 number 默认15秒
autoNext -- 是否自动播放下一首
autoplays -- 进入页面是否自动播放 - 默认false
slideYes -- 滑动进度条时是否开启播放 - 默认false
switAud -- 切换上下音频是否开启播放 - 默认false
BsNav -- 倍数数据传入/数组形式
按钮图片未自定义,如想改动请在组件内部修改,页面头部已注释 -- 逻辑根据自己需求改
目前只测试 微信小程序和H5和APP -- 其他平台未知
Author:chenxin 交流vx:cxalq8-24
*/
export default {
name: "cx-audio-play",
props: {
list: { //音频数据
Type: Array,
default: () => []
},
Faskms: { //快进秒数
Type: Number,
default: 15,
},
Slowms: { //快退秒数
Type: Number,
default: 15,
},
autoNext: {
Type: Boolean,
default: false,
},
autoplays: { //是否开启自动播放
Type: Boolean,
default: false,
},
slideYes: { //滑动进度条 - 是否开启播放
Type: Boolean,
default: false,
},
switAud: {
Type: Boolean, //切换上下音频 - 是否开启播放
default: false,
},
BsNav: { //倍数-传入
Type: Array,
default: () => [{
id: 1.0,
bs: '1.0',
}, {
id: 1.5,
bs: '1.5'
}, {
id: 2.0,
bs: '2.0'
}],
},
},
data() {
return {
shows: false, //倍数弹框
show: true, //倍数弹框动画默认开启
jian: true, //减-切换图标
jia: true, //加-切换图标
succes: false, //播放按钮
bsid: '', //倍数默认显示第一个
bsindex: 0, //倍数默认显示第一个
num: 0,
current: 0, //当前选中的索引
recorPath: '', //音频播放地址
lock: false, // 锁
currentTime: 0, //当前进度
duration: 100, // 总进度
videoContext: null,
loading: true, //锁 加载
}
},
onReady() {},
onShow() {},
mounted() {
this.videoContext = uni.createVideoContext('myVideo', this)
//默认播放第一个 -- 按钮展示
if (this.list.length != 0) {
this.recorPath = this.list[0].recorPath
if (this.list.length > 1) { //音频文件大于1 -- 下一个切换默认显示
this.jia = false
if (this.autoplays) {
this.succes = true
}
}
}
//倍数默认处理
if (this.BsNav.length != 0) {
this.bsid = this.BsNav[0].id
this.$nextTick(() => {
//#ifdef H5
this.$refs.myVideo.playbackRate(this.bsid)
//#endif
//#ifndef H5
this.videoContext.playbackRate(this.bsid)
//#endif
})
}
},
updated() {
},
onLoad() {
},
onHide() { //监听页面离开 - 销毁音频
//#ifdef H5
this.$refs.myVideo.stop();
//#endif
//#ifndef H5
this.videoContext.stop();
//#endif
},
onUnload() { //监听页面卸载 - 销毁音频
//#ifdef H5
this.$refs.myVideo.stop();
//#endif
//#ifndef H5
this.videoContext.stop();
//#endif
},
destroyed() {
// this.innerAudioContext.stop();
},
computed: {
timer() {
return calcTimer(this.currentTime)
},
overTimer() {
return calcTimer(this.duration)
}
},
watch: {
},
methods: {
plays() { //播放暂停
if (!this.list || this.list.length == 0) {
console.log('暂无音频数据~')
return;
}
this.playloading()
this.succes = !this.succes
if (this.succes) {
// this.currentTime = 0
// console.log('-----------------')
//#ifdef H5
this.$refs.myVideo.play()
//#endif
//#ifndef H5
this.videoContext.play()
//#endif
} else {
uni.hideLoading()
//#ifdef H5
this.$refs.myVideo.pause()
//#endif
//#ifndef H5
this.videoContext.pause()
//#endif
}
},
beishu() { //倍速弹框
this.shows = !this.shows
},
// 倍速
setRate(index, item) {
this.bsid = item.id
this.bsindex = index
this.shows = false
//#ifdef H5
this.$refs.myVideo.playbackRate(item.id)
//#endif
//#ifndef H5
this.videoContext.playbackRate(item.id)
//#endif
},
// 更新进度条
timeupdate(event) {
if (this.lock) return; // 锁
var currentTime, duration;
if (event.detail.detail) {
currentTime = event.detail.detail.currentTime
duration = event.detail.detail.duration
} else {
currentTime = event.detail.currentTime
duration = event.detail.duration
}
this.currentTime = currentTime
this.duration = duration
},
// 拖动进度条
sliderChange(data) {
//此处滑动进度条--开始播放
if (this.slideYes && !this.succes) {
//#ifdef H5
this.$refs.myVideo.play()
//#endif
//#ifndef H5
this.videoContext.play()
//#endif
this.succes = true
}
//#ifdef H5
this.$refs.myVideo.seek(data.detail.value) //获取秒数
//#endif
//#ifndef H5
this.videoContext.seek(data.detail.value) //获取秒数
//#endif
},
//拖动中
sliderChanging(data) {
if (data.detail.value == 0) {
this.succes = false
//#ifdef H5
this.$refs.myVideo.pause()
//#endif
//#ifndef H5
this.videoContext.pause()
//#endif
}
this.currentTime = data.detail.value
},
// 视频加载完成
loadedmetadata(data) {
this.duration = data.detail.duration
},
sig() { //上一首
if (!this.list || this.list.length == 0) {
console.log('暂无音频数据~')
return;
}
this.num -= 1
if (this.num < this.list.length) {
this.loading = true
this.playloading() //加载框
}
if (this.num + 1 < this.list.length && this.num + 1 != 1) { //点击上一首小于音频数据总长度
this.jia = false // 下按钮-亮且可点击
this.jian = false // 上按钮-亮且可点击
} else {
this.jian = true // 上按钮-灰且阻止
this.jia = false // 下按钮-亮且可点击
}
this.recorPath = this.list[this.num].recorPath
if (this.switAud) { //切换时是否默认开启播放
this.succes = true
setTimeout(() => {
//#ifdef H5
this.$refs.myVideo.play()
//#endif
//#ifndef H5
this.videoContext.play()
//#endif
}, 100)
} else {
this.succes = false
}
},
xig() { //下一首
if (!this.list || this.list.length == 0) {
console.log('暂无音频数据~')
return;
}
this.num += 1
if (this.num < this.list.length) {
this.loading = true
this.playloading() //加载框
}
if (this.num + 1 < this.list.length) { //点击下一首小于音频数据总长度
this.jia = false // 下按钮-亮且可点击
this.jian = false // 上按钮-亮且可点击
} else { //大于总长度
this.jia = true //下按钮 - 灰且阻止
this.jian = false //上按钮 - 亮可点击
}
this.recorPath = this.list[this.num].recorPath
if (this.switAud) { //切换时是否默认开启播放
this.succes = true
setTimeout(() => {
//#ifdef H5
this.$refs.myVideo.play()
//#endif
//#ifndef H5
this.videoContext.play()
//#endif
}, 100)
} else {
this.succes = false
}
},
nosig() {
uni.showToast({
title: '到头了~',
icon: "none"
})
},
noxig() {
uni.showToast({
title: '没有更多了~',
icon: "none"
})
},
kt() { //快退
if (!this.list || this.list.length == 0) {
console.log('暂无音频数据~')
return;
}
let a = (this.currentTime - Math.floor(15 % 60)).toFixed(0) //当前时间-15秒
if (a < 1) {
this.succes = false
//#ifdef H5
this.$refs.myVideo.pause()
//#endif
//#ifndef H5
this.videoContext.pause()
//#endif
}
//#ifdef H5
this.$refs.myVideo.seek(a)
//#endif
//#ifndef H5
this.videoContext.seek(a)
//#endif
},
kj() { //快进
if (!this.list || this.list.length == 0) {
console.log('暂无音频数据~')
return;
}
let a = (this.currentTime + Math.floor(15 % 60)).toFixed(0) //当前时间+15秒
//#ifdef H5
this.$refs.myVideo.seek(a)
//#endif
//#ifndef H5
this.videoContext.seek(a)
//#endif
},
next(data) { //监听音频结束
this.succes = false
/*音频结束--是否自动播放下一首*/
if (!this.autoNext) {
return
}
if (this.num + 1 < this.list.length) {
this.succes = true
this.num += 1
this.recorPath = this.list[this.num].recorPath
setTimeout(() => {
//#ifdef H5
this.$refs.myVideo.play()
//#endif
//#ifndef H5
this.videoContext.play()
//#endif
}, 100)
} else {
this.jia = true //下按钮 - 灰且阻止
this.jian = false //上按钮 - 亮可点击
}
// console.log('音频结束-------')
},
playloading() { //加载框--封
if (this.loading) {
uni.showLoading({
title: "音频缓存中..."
})
this.loading = false
}
setTimeout(() => {
uni.hideLoading()
}, 1600)
},
},
watch: {}
}
//时间换算
function calcTimer(timer) {
if (timer === 0 || typeof timer !== 'number') {
return '00:00'
}
let mm = Math.floor(timer / 60)
let ss = Math.floor(timer % 60)
if (mm < 10) {
mm = '0' + mm
}
if (ss < 10) {
ss = '0' + ss
}
return mm + ':' + ss
}
</script>
<style lang="scss" scoped>
page {
background-color: #F6F6F8;
}
/* #video {
width: 100%;
} */
.audo-video {
padding-bottom: 20rpx;
color: #999;
}
.slider-box {
display: flex;
align-items: center;
justify-content: center;
font-size: 27rpx;
color: #999;
}
button {
display: inline-block;
width: 100rpx;
background-color: #fff;
font-size: 24rpx;
color: #000;
padding: 0;
}
.hidden {
position: fixed;
top: 0;
left: -10rpx;
z-index: -1;
width: 1rpx;
height: 1rpx;
}
.audo-top {
padding: 20rpx 40rpx;
display: flex;
justify-content: space-around;
align-items: center;
image {
width: 45rpx;
height: 45rpx;
}
}
.audo-a {
display: flex;
justify-content: space-between;
align-items: center;
width: 700rpx;
position: relative;
z-index: 9;
}
.beishu {
position: relative;
width: 100rpx;
padding-top: 5rpx;
padding-bottom: 5rpx;
text-align: center;
border-radius: 25rpx;
font-size: 28rpx;
}
.absolute {
position: absolute;
.beishu-a {
width: 200rpx;
border-radius: 20rpx;
text-align: center;
line-height: 90rpx;
background: #fff;
.title {
pdding-left: 30rpx;
}
}
}
</style>

View File

@@ -0,0 +1,85 @@
{
"id": "cx-audio-play",
"displayName": "音频播放组件,自定义修改",
"version": "2.0.1",
"description": "音频播放组件兼容微信小程序、h5等可倍数播放快进快退切换上下音频等",
"keywords": [
"音频",
"音频播放",
"播放器",
"倍数播放",
"播放"
],
"repository": "",
"engines": {
"HBuilderX": "^3.5.5"
},
"dcloudext": {
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "插件不采集任何数据",
"permissions": "无"
},
"npmurl": "",
"type": "component-vue"
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"Vue": {
"vue2": "y",
"vue3": "u"
},
"App": {
"app-vue": "y",
"app-nvue": "u"
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "y",
"IE": "y",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "y",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
### 组件各参说明 :
____
#### 1. 实现切换上下首、自动播放、倍数播放、快进快退、进度条播放等
#### 2. list 【Array】 音频数据/不传无法播放
#### 3. Seconds 【number】 快进快退秒数 - 默认15秒
#### 4. autoNext 【Boolean】 自动播放下一首 - 默认不开启
#### 5. autoplays 【Boolean】 进入页面是否自动播放 - 默认不开启
#### 6. slideYes 【Boolean】 拖动进度条时开启播放 - 默认不开启
#### 7. switAud 【Boolean】 切换上下音频开启播放 - 默认开启
#### 8. BsNav 【Array】 倍数数据
#### 本音频组件扩展性强样式功能随意调整兼容H5微信小程序App建议下载示例项目避免因图片缺失引起报错谢谢支持~
#### 作者: chenxin ,微信交流: cxalq8-24
----

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -1 +0,0 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1703664219110" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7586" xmlns:xlink="http://www.w3.org/1999/xlink" width="128" height="128"><path d="M46.08 272.213333a42.666667 42.666667 0 0 0 8.96 14.08l128 128a42.666667 42.666667 0 0 0 60.586667 0 42.666667 42.666667 0 0 0 0-60.586666L188.16 298.666667H704a192.426667 192.426667 0 0 1 192 192 42.666667 42.666667 0 0 0 85.333333 0A277.76 277.76 0 0 0 704 213.333333H188.16l55.466667-55.04a42.666667 42.666667 0 0 0-60.586667-60.586666l-128 128a42.666667 42.666667 0 0 0-8.96 14.08 42.666667 42.666667 0 0 0 0 32.426666zM977.92 751.786667a42.666667 42.666667 0 0 0-8.96-14.08l-128-128a42.666667 42.666667 0 0 0-60.586667 60.586666l55.466667 55.04H320A192.426667 192.426667 0 0 1 128 533.333333a42.666667 42.666667 0 0 0-85.333333 0A277.76 277.76 0 0 0 320 810.666667h515.84l-55.466667 55.04a42.666667 42.666667 0 0 0 0 60.586666 42.666667 42.666667 0 0 0 60.586667 0l128-128a42.666667 42.666667 0 0 0 8.96-14.08 42.666667 42.666667 0 0 0 0-32.426666z" p-id="7587" fill="#3d3d3d"></path></svg>

Before

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><defs><style>.a,.b{fill:none;}.b{stroke:#3d3d3d;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-width:1.5px;}.c{}</style></defs><rect class="a" width="24" height="24"/><path class="b" d="M1515.681,625a8,8,0,1,1,0-8v-4" transform="translate(-1496.22 -609)"/><path class="c" d="M3.17,0V-7.12H1.83L.74-6.27v1.5l1.09-.78V0ZM7.95-2.47a3.4,3.4,0,0,0-.33-1.9,1.206,1.206,0,0,0-1.04-.45,1.135,1.135,0,0,0-.51.13,1.407,1.407,0,0,0-.39.34V-5.92H7.87v-1.2H4.46v4.04H5.74v-.05c0-.33.18-.49.42-.49a.389.389,0,0,1,.36.21,3.037,3.037,0,0,1,.09,1.07,3.166,3.166,0,0,1-.12,1.22.359.359,0,0,1-.33.16c-.24,0-.42-.16-.42-.49v-.49H4.4v.28A1.579,1.579,0,0,0,4.89-.38,1.822,1.822,0,0,0,6.16.08,1.869,1.869,0,0,0,7.43-.38,2.647,2.647,0,0,0,7.95-2.47Z" transform="translate(8.26 15.52)"/><rect class="c" width="5.5" height="1.5" rx="0.75" transform="translate(17.5 11.23)"/><rect class="c" width="5.5" height="1.5" rx="0.75" transform="translate(21 9.23) rotate(90)" /></svg>

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><defs><style>.a,.b{fill:none;}.b{stroke:#475266;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-width:1.5px;}.c{color:'#3d3d3d'}</style></defs><rect class="a" width="24" height="24"/><g transform="translate(-1496.22 -609)"><path class="b" d="M1500.76,625a8,8,0,1,0,0-8v-4"/></g><path class="c" d="M3.17,0V-7.12H1.83L.74-6.27v1.5l1.09-.78V0ZM7.95-2.47a3.4,3.4,0,0,0-.33-1.9,1.206,1.206,0,0,0-1.04-.45,1.135,1.135,0,0,0-.51.13,1.407,1.407,0,0,0-.39.34V-5.92H7.87v-1.2H4.46v4.04H5.74v-.05c0-.33.18-.49.42-.49a.389.389,0,0,1,.36.21,3.037,3.037,0,0,1,.09,1.07,3.166,3.166,0,0,1-.12,1.22.359.359,0,0,1-.33.16c-.24,0-.42-.16-.42-.49v-.49H4.4v.28A1.579,1.579,0,0,0,4.89-.38,1.822,1.822,0,0,0,6.16.08,1.869,1.869,0,0,0,7.43-.38,2.647,2.647,0,0,0,7.95-2.47Z" transform="translate(7 15.5)"/><rect class="c" width="4.5" height="1.5" rx="0.75" transform="translate(2 11.23)"/></svg>

Before

Width:  |  Height:  |  Size: 975 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><defs><style>.a{fill:none;}.b,.c{fill:#475266;}.c{font-size:8px;font-family:PingFangSC-Semibold, PingFang SC;font-weight:600;letter-spacing:-0.02em;}</style></defs><rect class="a" width="24" height="24"/><path class="b" d="M1530.26,598.75V604a2.5,2.5,0,0,1-2.5,2.5h-16a2.5,2.5,0,0,1-2.5-2.5V594a2.5,2.5,0,0,1,2.5-2.5h7.25a.75.75,0,0,0,.75-.75h0a.75.75,0,0,0-.75-.75h-7.25a4,4,0,0,0-4,4v10a4,4,0,0,0,4,4h16a4,4,0,0,0,4-4v-5.25a.75.75,0,0,0-.75-.75h0A.75.75,0,0,0,1530.26,598.75Z" transform="translate(-1507.76 -587)"/><text class="c" transform="translate(4 15)"><tspan x="0" y="0">倍速</tspan></text></svg>

Before

Width:  |  Height:  |  Size: 690 B

View File

@@ -1 +0,0 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1703643608574" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7023" xmlns:xlink="http://www.w3.org/1999/xlink" width="128" height="128"><path d="M256 810.666667h170.666667V213.333333H256v597.333334z m341.333333-597.333334v597.333334h170.666667V213.333333h-170.666667z" p-id="7024"></path></svg>

Before

Width:  |  Height:  |  Size: 482 B

View File

@@ -1 +0,0 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1703643757308" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8148" xmlns:xlink="http://www.w3.org/1999/xlink" width="128" height="128"><path d="M820.053 473.316l-527.929-327.68c-29.582-18.205-68.266 4.55-68.266 38.684v655.36c0 34.133 38.684 56.889 68.266 38.684l525.654-327.68c31.858-15.928 31.858-61.44 2.275-77.368z" p-id="8149"></path></svg>

Before

Width:  |  Height:  |  Size: 533 B