<view class="uni-list">
<view class="uni-list-cell">
<view>
<view class="uni-label">弹幕内容</view>
</view>
<view class="uni-list-cell-db">
<input @blur="bindInputBlur" class="uni-input" type="text" placeholder="在此处输入弹幕内容" />
</view>
</view>
</view>
<view class="btn-area">
<button @tap="bindSendDanmu" class="page-body-button" formType="submit">发送弹幕</button>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'video',
src: 'http://vjs.zencdn.net/v/oceans.mp4',
inputValue: '',
danmuList: [{
text: '第 1s 出现的弹幕',
color: '#ff0000',
time: 1
},
{
text: '第 3s 出现的弹幕',
color: '#ff00ff',
time: 3
}
]
}
},
onLoad() {
this.videoContext = uni.createVideoContext('myVideo')
},
onReady: function (res) {
this.videoContext = uni.createVideoContext('myVideo')
},
methods: {
bindInputBlur: function (e) {
this.inputValue = e.target.value
},
bindButtonTap: function () {
var that = this
uni.chooseVideo({
sourceType: ['album', 'camera'],
maxDuration: 60,
camera: ['front', 'back'],
success: function (res) {
this.src = res.tempFilePath
}
})
},
bindSendDanmu: function () {
this.videoContext.sendDanmu({
text: this.inputValue,
color: this.getRandomColor()
})
},
videoErrorCallback: function (e) {
console.log('视频错误信息:')
console.log(e)
},
getRandomColor: function () {
const rgb = []
for (let i = 0; i < 3; ++i) {
let color = Math.floor(Math.random() * 256).toString(16)
color = color.length == 1 ? '0' + color : color
rgb.push(color)
}
return '#' + rgb.join('')
}
}
}
</script>
- 发布:2021-03-02 15:01
- 更新:2023-06-19 23:37
- 阅读:7859
【报Bug】使用video组件,内置浏览器报错:Uncaught (in promise)DOMException: The element has no supported sources.
产品分类: HbuilderX
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win7 64位
HBuilderX版本号: 2.9.8
示例代码:
<template>
<view>
<view class="page-body">
<view class="page-section">
<video id="myVideo" crossOrigin="anonymous" src="http://vjs.zencdn.net/v/oceans.mp4" @error="videoErrorCallback" :danmu-list="danmuList"
enable-danmu danmu-btn controls></video>
操作步骤:
<template>
<view>
<view class="page-body">
<view class="page-section">
<video id="myVideo" crossOrigin="anonymous" src="http://vjs.zencdn.net/v/oceans.mp4" @error="videoErrorCallback" :danmu-list="danmuList"
enable-danmu danmu-btn controls></video>
<view class="uni-list">
<view class="uni-list-cell">
<view>
<view class="uni-label">弹幕内容</view>
</view>
<view class="uni-list-cell-db">
<input @blur="bindInputBlur" class="uni-input" type="text" placeholder="在此处输入弹幕内容" />
</view>
</view>
</view>
<view class="btn-area">
<button @tap="bindSendDanmu" class="page-body-button" formType="submit">发送弹幕</button>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'video',
src: 'http://vjs.zencdn.net/v/oceans.mp4',
inputValue: '',
danmuList: [{
text: '第 1s 出现的弹幕',
color: '#ff0000',
time: 1
},
{
text: '第 3s 出现的弹幕',
color: '#ff00ff',
time: 3
}
]
}
},
onLoad() {
this.videoContext = uni.createVideoContext('myVideo')
},
onReady: function (res) {
this.videoContext = uni.createVideoContext('myVideo')
},
methods: {
bindInputBlur: function (e) {
this.inputValue = e.target.value
},
bindButtonTap: function () {
var that = this
uni.chooseVideo({
sourceType: ['album', 'camera'],
maxDuration: 60,
camera: ['front', 'back'],
success: function (res) {
this.src = res.tempFilePath
}
})
},
bindSendDanmu: function () {
this.videoContext.sendDanmu({
text: this.inputValue,
color: this.getRandomColor()
})
},
videoErrorCallback: function (e) {
console.log('视频错误信息:')
console.log(e)
},
getRandomColor: function () {
const rgb = []
for (let i = 0; i < 3; ++i) {
let color = Math.floor(Math.random() * 256).toString(16)
color = color.length == 1 ? '0' + color : color
rgb.push(color)
}
return '#' + rgb.join('')
}
}
}
</script>
<view class="uni-list">
<view class="uni-list-cell">
<view>
<view class="uni-label">弹幕内容</view>
</view>
<view class="uni-list-cell-db">
<input @blur="bindInputBlur" class="uni-input" type="text" placeholder="在此处输入弹幕内容" />
</view>
</view>
</view>
<view class="btn-area">
<button @tap="bindSendDanmu" class="page-body-button" formType="submit">发送弹幕</button>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'video',
src: 'http://vjs.zencdn.net/v/oceans.mp4',
inputValue: '',
danmuList: [{
text: '第 1s 出现的弹幕',
color: '#ff0000',
time: 1
},
{
text: '第 3s 出现的弹幕',
color: '#ff00ff',
time: 3
}
]
}
},
onLoad() {
this.videoContext = uni.createVideoContext('myVideo')
},
onReady: function (res) {
this.videoContext = uni.createVideoContext('myVideo')
},
methods: {
bindInputBlur: function (e) {
this.inputValue = e.target.value
},
bindButtonTap: function () {
var that = this
uni.chooseVideo({
sourceType: ['album', 'camera'],
maxDuration: 60,
camera: ['front', 'back'],
success: function (res) {
this.src = res.tempFilePath
}
})
},
bindSendDanmu: function () {
this.videoContext.sendDanmu({
text: this.inputValue,
color: this.getRandomColor()
})
},
videoErrorCallback: function (e) {
console.log('视频错误信息:')
console.log(e)
},
getRandomColor: function () {
const rgb = []
for (let i = 0; i < 3; ++i) {
let color = Math.floor(Math.random() * 256).toString(16)
color = color.length == 1 ? '0' + color : color
rgb.push(color)
}
return '#' + rgb.join('')
}
}
}
</script>
预期结果:
可以播放视频
可以播放视频
实际结果:
Uncaught (in promise)DOMException: The element has no supported sources.
Uncaught (in promise)DOMException: The element has no supported sources.
bug描述:
使用video组件,点击视频播放但是报错:Uncaught (in promise)DOMException: The element has no supported sources.
佬马识途 - 80后IT哥
今天也遇到这个问题了, 都23年中了还没修复
-
这个错误的原因通常是 video 组件的 src 属性设置不正确或者视频资源路径不正确。可能是以下几个原因导致的:
视频资源路径不正确,需要检查视频文件的路径是否正确。
视频资源的格式不被内置浏览器支持,这种情况下需要检查视频文件的格式是否正确,并且要注意不同内置浏览器支持的视频格式可能不同。
在设置 video 组件的 src 属性时,需要设置正确的类型,例如:
<video :src="videoSrc" type="video/mp4"></video>
其中的 type 值表示视频文件的类型,需要根据实际情况进行设置。
如果以上方法都不能解决问题,可以在内置浏览器的开发者工具中查看具体的错误信息,以便更好地进行排查和解决。
2023-06-20 06:47
刘超群
光记录不修复,有个毛用
2021-07-07 09:59
天机不可泄露
我APP端正常播放,H5也是报这个错,你记100遍问题也还是存在,就算暂时解决不了也要拿个替代方案出来啊
2021-10-18 19:04
l***@163.com
过去一年多了,还是没有解决,你们能解决不?
2022-09-06 14:25