阿里云Web播放器Web端使用SDK说明:https://help.aliyun.com/document_detail/51991.html?spm=5176.11065259.1996646101.searchclickresult.15a92458LoTQhA

vue项目中要使用阿里云的播放器,步骤如下:

先在index.html中引入需要的js,css

<link rel="stylesheet" href="//g.alicdn.com/de/prismplayer/2.7.2/skins/default/aliplayer-min.css" />
<script src="//g.alicdn.com/de/prismplayer/2.7.2/aliplayer-h5-min.js"></script>
<script src="//g.alicdn.com/de/prismplayer/2.7.2/json/json.min.js"></script>

Vue组件中

template代码:

<section class="playBox prism-player videoplayIfram"  id="AlivideoPlay"></section>

id是必须的

script代码:

aliyunPlay () {
/* eslint-disable */
this.player = new Aliplayer({
id: 'AlivideoPlay', // template里定义的部分
width: '100%',
height: '100%',
vid : this.AliUrl, // url (必须)
playauth : this.playauth, // (必须)
showBarTime: ,
qualitySort: "asc"
}, function (player) {
// console.log("播放器创建成功");
});
}

Vue完整代码:

<template>
<transition name="slide">
<div class="videoplayback">
<div class="videoPlayTop">
<div class="passwordTip" v-show="ifShowPassword">播放密码:{{passwordTip}}</div>
<div class="goBack" @click="videoplayHidden">
<div class="imgDiv">
<img src="http://static.crecgec.com/wxmobile/left_arrow.png"/>
</div>
</div>
<div class="videoOperation" @click="changeVocon">
<div class="videoOperationImg">
<img src="http://static.crecgec.com/wxmobile/videoOperation.png"/>
</div>
</div>
</div>
<div class="videoplay" ref='videoplay'>
<!--<iframe class="videoplayIfram" :src='AliUrl' frameborder= ></iframe>-->
<section class="playBox prism-player videoplayIfram" id="AlivideoPlay"></section>
<!-- <div class="prism-player videoplayIfram" id="prismPlayer"></div> -->
<div class="noVideoPlay" v-show="noVideoPlayShow">视频暂时无法播放</div>
</div>
<div class="videoOperationCon" v-show="voconShow">
<div class="voconItem" v-if="favorite === null" @click="collectionYes">
<div class="divImg">
<img src="http://static.crecgec.com/wxmobile/collection.png"/>
</div>
<div class="divVal">收藏</div>
</div>
<div class="voconItem" v-else @click="collectionNo">
<div class="divImg">
<img src="http://static.crecgec.com/wxmobile/collectionHas.png"/>
</div>
<div class="divVal">已收藏</div>
</div>
<div class="voconItem" @click='shareopen'>
<div class="divImg">
<img src="http://static.crecgec.com/wxmobile/share.png"/>
</div>
<div class="divVal">分享</div>
</div>
<div class="voconItem" @click="commentConShow">
<div class="divImg">
<img src="http://static.crecgec.com/wxmobile/scorEoperation.png"/>
</div>
<div class="divVal">评分</div>
</div>
</div>
<div class="commentShow" v-show="commentShow">
<div class="commentCon">
<div class="closeCommentCon">
<a class="commentConClose" @click.stop="commentConClose">
<div class="commentConCloseImg">
<img src="http://static.crecgec.com/wxmobile/close.png"/>
</div>
</a>
</div>
<van-rate
class="scroeRate"
v-model="scoreVal"
:size=""
:count=""
color="#398ed1"
void-color="#ceefe8"
/>
<a class="commentSubmit" @click.stop="commentSubmit">提交</a>
</div>
</div>
<div class="playTitle">{{playTitle}}</div>
<div class="playDetails">
<div class="detailsPlay">
<div class="classHour">共{{classHour}}课时</div>
<a class="goCourseDetail" @click="videoplayHidden">课程详情></a>
</div>
</div>
<div class="catalog-list">
<ul v-if="catalogList.length > 0">
<li v-for="(item, index) in catalogList" :key="index" @click="changeVideoPlay(index)">
<div class="catalog-list-title">{{item.sc_name}}</div>
</li>
</ul>
<div class="noLists" v-else>没有数据</div>
</div>
<!-- 分享 -->
<van-actionsheet v-model="shareSelect" title="分享" class="shareCh">
<div class="bdsharebuttonbox bdshare-button-style0-32">
<div class="shareline" @click='Qzshare'>
<a class="bds_qzone" data-cmd="qzone" href="javascript:;"></a>
<p>QQ空间</p>
</div>
<div class="shareline" @click='tsina'>
<a class="bds_tsina" data-cmd="tsina" href="javascript:;"></a>
<p>微博</p>
</div>
<div class="shareline" v-clipboard:copy="copyUrl" v-clipboard:success="onCopy" v-clipboard:error="onError">
<a class="bds_copyurl" data-cmd="copyurl" href="javascript:;"></a>
<p>复制链接</p>
</div>
</div>
</van-actionsheet>
</div>
</transition>
</template> <script type="text/ecmascript-6">
import {mapGetters} from 'vuex'
import bdshare from 'bdshare'
import { Toast } from 'vant'
/*
import 'common/js/aliplayer-h5-min.js'
import 'common/js/json.min.js'
*/ export default {
props: {
catalogList: {
type: Array,
default: () => []
},
lession: {},
favorite: '',
videoPlayIndex: {
type: Number,
default:
},
c_id: {
type: Number,
default:
},
videoplayShow: {
type: Boolean,
default: false
}
},
data () {
return {
videoSrc: '',
playTitle: '',
classHour: ,
voconShow: false,
isCollect: false,
scoreVal: , // 当前分值
commentShow: false,
AliUrl: '', // 视频url
vid: '',
playauth: '',
shareSelect: false,
noVideoPlayShow: false,
passwordTip: '',
ifShowPassword: false,
copyUrl: window.location.href,
submitIsCollection: true,
s_id: '', // 课时ID
player: null,
shareConfig: {
bdText: this.$store.state.courseName,
bdUrl: this.$store.state.bdUrl,
bdPic: this.$store.state.bdPic
}
}
},
watch: {
videoplayShow (val) {
if (val === true) {
this.classHour = this.catalogList.length
if (this.catalogList.length > ) {
this.changeVideoPlay(this.videoPlayIndex)
}
}
}
},
methods: {
videoplayHidden () {
this.voconShow = false
this.$emit('videoHidden', false)
},
changeVideoPlay (index) {
if (this.player) {
this.player.dispose()
var oSection = document.createElement('section')
oSection.className = 'playBox prism-player videoplayIfram'
oSection.id = 'AlivideoPlay'
this.$refs.videoplay.appendChild(oSection)
}
this.videoOverdue(this.catalogList[index].id, index)
},
changeVocon () {
this.voconShow = !this.voconShow
},
// 收藏
collectionYes () {
let _this = this
if (this.submitIsCollection) {
this.submitIsCollection = false
_this.axios({
method: 'post',
url: _this.api.course.favorite,
data: {
cid: this.c_id,
token: _this.api.token,
client: _this.api.encodeClient
}
})
.then(function (response) {
if (response.status === && response.data.states === true) {
_this.$emit('changeFavorites', true)
}
_this.submitIsCollection = true
})
.catch(function (error) {
console.log(error)
_this.submitIsCollection = true
})
}
},
// 取消收藏
collectionNo () {
let _this = this
if (this.submitIsCollection) {
_this.axios({
method: 'post',
url: _this.api.course.unfavorite,
data: {
cid: this.c_id,
token: _this.api.token,
client: _this.api.encodeClient
}
})
.then(function (response) {
if (response.status === && response.data.states === true) {
_this.$emit('changeFavorites', true)
}
_this.submitIsCollection = true
})
.catch(function (error) {
console.log(error)
_this.submitIsCollection = true
})
}
},
// 评分提交
commentSubmit () {
let _this = this
_this.axios({
method: 'post',
url: _this.api.course.ajaxpinglunadd,
data: {
sec_score: this.scoreVal,
s_id: this.s_id,
c_id: this.c_id,
token: _this.api.token,
client: _this.api.encodeClient
}
})
.then(function (response) {
if (response.status === && response.data.success === true) {
_this.$toast('评分成功!')
_this.evaluation = ''
_this.commentConClose()
}
})
.catch(function (error) {
console.log(error)
})
},
// 打开评分弹出层
commentConShow () {
this.commentShow = true
},
// 关闭评分弹出层
commentConClose () {
this.commentShow = false
},
shareopen () {
this.shareSelect = true
},
Qzshare () {
bdshare.qzone(this.shareConfig)
},
tsina () {
bdshare.tsina(this.shareConfig)
},
// 查看课程视频是否过期
videoOverdue (id, index) {
let _this = this
_this.axios({
method: 'get',
url: _this.api.course.study,
params: {
id: id,
token: _this.api.token,
client: _this.api.encodeClient
}
})
.then(function (response) {
if (response.status === && response.data.state === true) {
_this.noVideoPlayShow = false
_this.passwordTip = _this.catalogList[index].playpass
if (_this.catalogList[index].videolocation === 'aliyun') {
_this.ifShowPassword = false
} else {
_this.ifShowPassword = true
}
_this.AliUrl = response.data.data.lession.yun_url
_this.playauth = response.data.data.lession.PlayAuth
_this.playTitle = _this.catalogList[index].sc_name
_this.s_id = _this.catalogList[index].id
_this.aliyunPlay()
} else {
_this.noVideoPlayShow = true
}
})
.catch(function (error) {
console.log(error)
})
},
onCopy (e) {
this.shareSelect = false
Toast('复制链接成功')
},
onError () {
this.shareSelect = false
Toast('复制链接失败')
},
aliyunPlay () {
/* eslint-disable */
this.player = new Aliplayer({
id: 'AlivideoPlay',
width: '100%',
height: '100%',
vid : this.AliUrl,
playauth : this.playauth,
showBarTime: ,
qualitySort: "asc"
}, function (player) {
// console.log("播放器创建成功");
});
}
},
components: {
...mapGetters([
'courseName', 'bdUrl', 'bdPic'
])
}
}
</script> <style scoped lang="less" rel="stylesheet/less" type="text/less">
@import "../../common/less/variable"; .videoplayback{
position: absolute;
z-index: ;
top: -90px;
bottom: ;
left: ;
right: ;
background-color: #f3f5f7;
.videoPlayTop{
position: relative;
height: 90px;
background-color: rgba(, , , 0.7);
.goBack{
margin-left: 10px;
width: 58px;
height: 90px;
vertical-align: middle;
text-align: center;
display: flex;
justify-content:center;
align-items:Center;
float: left;
.imgDiv{
width: 18px;
height: 30px;
img{
display: inline-block;
float: left;
width: %;
height: %;
}
}
}
.passwordTip{
position: absolute;
left: %;
top: %;
transform: translate(-%, -%);
color: #fff;
font-size: 28px;
}
.videoOperation{
width: 80px;
height: 90px;
float: right;
margin-right: 10px;
display: flex;
justify-content:center;
align-items:Center;
.videoOperationImg{
width: 30px;
height: 6px;
img{
display: inline-block;
float: left;
width: %;
height: %;
}
}
}
}
.videoplay{
width: %;
height: 420px;
background-color: rgba(, , , 0.7);
position: relative;
.videoplayIfram{
width: %;
height: 420px;
}
.noVideoPlay{
position: absolute;
color: #fff;
left: %;
top: %;
transform: translate(-%, -%);
}
}
.videoOperationCon{
position: absolute;
background-color: #fff;
border-radius: 4px;
margin-top: 10px;
top: 80px;
right: 30px;
display: flex;
flex-direction: column;
padding-bottom:26px;
padding-right: 26px;
padding-left: 26px;
.voconItem{
line-height: 28px;
padding-top: 26px;
&:first-child{
padding-top: 22px;
}
.divImg{
width: 30px;
height: 28px;
display: inline-block;
img{
vertical-align: top;
width: %;
height: %;
}
}
.divVal{
display: inline-block;
font-size: @font-size-;
color: #;
margin-left: 10px;
}
}
}
.commentShow{
position: fixed;
left: ;
top: ;
right: ;
bottom: ;
z-index: ;
background-color: rgba(, , , 0.5);
.commentCon{
position: absolute;
width: %;
padding-bottom: 50px;
/*height: 200px;*/
background-color: #fff;
left: %;
top: %;
transform: translate(-%, -%);
border: 1px solid #eeeeee;
border-radius: 10px;
.closeCommentCon{
overflow: hidden;
.commentConClose{
float: right;
padding: 10px;
margin-right: 10px;
.commentConCloseImg{
width: 30px;
height: 30px;
img{
width: %;
height: %;
}
}
}
}
.scroeRate{
margin-top: 10px;
}
.commentSubmit{
display: inline-block;
padding: 5px 10px;
color: #fff;
font-size: @font-size-;
line-height: 40px;
border-radius: 10px;
background-color: #398ed1;
margin-top: 30px;
}
}
}
.playTitle{
color: #;
font-size: @font-size-;
text-align: left;
background-color: #fff;
padding: 40px 30px;
font-weight: bold;
}
.playDetails{
padding: 20px 30px ;
margin-top: 20px;
background-color: #ffffff;
overflow: hidden;
.detailsPlay{
border-bottom: 1px solid #dcdcdc;
overflow: hidden;
padding-bottom: 20px;
.classHour{
float: left;
color: #;
font-size: @font-size-;
}
.goCourseDetail{
float: right;
color: #8a8a8a;
font-size: @font-size-;
}
}
}
.catalog-list{
text-align: left;
background-color: #fff;
overflow: hidden;
ul{
overflow: hidden;
padding: 10px 30px;
li{
margin: 30px 30px ;
line-height: 24px;
overflow: hidden;
.catalog-list-title{
float: left;
margin-left: 20px;
color: #;
font-size: @font-size-;
}
}
.on{
.catalog-list-title{
color: #398ed1;
}
}
}
.noLists{
overflow: hidden;
padding: 20px;
font-size: @font-size-;
text-align: center;
}
}
}
.slide-enter-active,.slide-leave-active{
transition: all .3s
}
.slide-enter,.slide-leave-to{
transform: translate3d(%, , )
}
.shareCh{
overflow: hidden;
.shareline{
height: 120px;
width: 150px;
padding-top:36px;
text-align:center;
float: left;
overflow: hidden;
}
.bdshare-button-style0- a{
height: 50px;
width: 32px;
display: block;
margin: auto;
float: initial;
}
.bdshare-button-style0- p{
font-size: @font-size-;
}
.bdshare-button-style0- a.bds_qzone{
background: url(http://static.crecgec.com/wxmobile/kongjian.png) 0 0 no-repeat;
background-size: % auto;
}
.bdshare-button-style0- a.bds_tsina{background: url(http://static.crecgec.com/wxmobile/weibo.png) 0 0 no-repeat;
background-size: % auto;}
.bdshare-button-style0- a.bds_copyurl{background: url(http://static.crecgec.com/wxmobile/copyUrl.png) 0 0 no-repeat;
background-size: % auto;}
}
</style>

demo地址下载

vue中引入js,然后new js里的方法的更多相关文章

  1. iOS之在webView中引入本地html,image,js,css文件的方法 - sky//////////////////////////////////////ZZZZZZZZZZZZZZZ

    iOS之在webView中引入本地html,image,js,css文件的方法   2014-12-08 20:00:16CSDN-sky_2016-点击数:10292     项目需求 最近开发的项 ...

  2. react项目中引入了redux后js控制路由跳转方案

    如果你的项目中并没有用到redux,那本文你可以忽略 问题引入 纯粹的单页面react应用中,通过this.props.history.push('/list')就可以进行路由跳转,但是加上了redu ...

  3. vue中引入mintui、vux重构简单的APP项目

    最近在学习vue时也了解到一些常用的UI组件,有用于PC的和用于移动端的.用于PC的有:Element(饿了么).iView等:用于移动端APP的有Vux.Mint UI(饿了么).Vant(有赞团队 ...

  4. vue中引入babel步骤

    vue中引入babel步骤 vue项目中普遍使用es6语法,但有时我们的项目需要兼容低版本浏览器,这时就需要引入babel插件,将es6转成es5. 1.安装babel-polyfill插件 npm ...

  5. vue中引入json数据,不用本地请求

    1.我的项目结构,需要在Daily.vue中引入daily.js中的json数据 2.把json数据放入一个js文件中,用exports导出,vscode的json格式太严格了,很多数据,调了一个多小 ...

  6. vue中引入mui报Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them的错误

    在vue中引入mui的js文件的时候,报如下的错误: 那是因为我们在用webpack打包项目时默认的是严格模式,我们把严格模式去掉就ok了 第一步:npm install babel-plugin-t ...

  7. vue 中引入第三方js库

    以 jQuery 为例 一.绝对路径直接引入,全局可用 主入口页面 index.html 中用 script 标签引入: <script src="./static/jquery-1. ...

  8. 对vue中 默认的 config/index.js:配置的详细理解 -【以及webpack配置的理解】-config配置的目的都是为了服务webpack的配置,给不同的编译条件提供配置

    当我们需要和后台分离部署的时候,必须配置config/index.js: 用vue-cli 自动构建的目录里面  (环境变量及其基本变量的配置) var path = require('path') ...

  9. Vue中结合Flask与Node.JS的异步加载功能实现文章的分页效果

    你好!欢迎阅读我的博文,你可以跳转到我的个人博客网站,会有更好的排版效果和功能. 此外,本篇博文为本人Pushy原创,如需转载请注明出处:http://blog.pushy.site/posts/15 ...

随机推荐

  1. T-SQL 编程技巧

    Ø  T-SQL 编程是大多数程序员都会接触的,也是数据库编程必须掌握的技术.下面,是本人在工作或学习中积累的一些心得和技巧.主要包含以下内容: 1.   waitfor延时执行 2.   NOT 关 ...

  2. List、Map、set的加载因子,默认初始容量和扩容增量

    首先,这三个概念说下.初始大小,就是创建时可容纳的默认元素个数:加载因子,表示某个阀值,用0~1之间的小数来表示,当已有元素占比达到这个阀值后,底层将进行扩容操作:扩容方式,即指定每次扩容后的大小的规 ...

  3. linux上安装mysql,tomcat,jdk

    Linux 上安装 1 安装jdk 检测是否安装了jdk 运行 java –version 若有 需要将其卸载 a)         查看安装哪些jdk rmp –qa |grep java b)   ...

  4. GCC编译器原理(一)03------GCC 工具:gprof、ld、libbfd、libiberty 和libopcodes

    1.3.7 gprof:性能分析工具 参考文档:https://www.cnblogs.com/andashu/p/6378000.html gprof是GNU profile工具,可以运行于linu ...

  5. 【PgSQL安装(含配置)】PostgreSQL简称PgSQL,是1980以加利福尼亚大学开发的DBMS,严格遵守标准SQL。

    [下载地址]http://www.enterprisedb.com/products-services-training/pgdownload#windows …………………………………………………… ...

  6. [C++]PAT乙级1008.数组元素循环右移问题 (20/20)

    /* 1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数, ...

  7. A Bayesian Approach to Deep Neural Network Adaptation with Applications to Robust Automatic Speech Recognition

    基于贝叶斯的深度神经网络自适应及其在鲁棒自动语音识别中的应用     直接贝叶斯DNN自适应 使用高斯先验对DNN进行MAP自适应 为何贝叶斯在模型自适应中很有用? 因为自适应问题可以视为后验估计问题 ...

  8. sqlserver分组统计合并

    ---分组partition by;统计:Count();合并:for xml path('') with cte as( select COUNT(t2.Id) OVER(PARTITION BY ...

  9. Tip:什么是JavaBean

    可视化JavaBean  非可视化JavaBean(分:值JavaBean和工具JavaBean) JavaBean是一个遵循特定写法的Java类,它通常具有如下特点: 这个Java类必须具有一个无参 ...

  10. light oj 1011 - Marriage Ceremonies

    题目大意: 给出n*n的矩阵Map,Map[i][j]代表第i个男人和第j个女人之间的满意度,求男女一一配对后,最大的满意度之和. 题目思路:状态压缩 题目可看做每行取一点,所有点不同列的情况下,各个 ...