Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Commit

Permalink
修复相对路径声音无法播放的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
HCLonely committed Apr 14, 2020
1 parent fbbc722 commit 084552c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<script src="https://cubism.live2d.com/sdk-web/cubismcore/live2dcubismcore.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/pixi.js@4.6.1/dist/pixi.min.js"></script>
<!-- live2dv3.js -->
<script src="https://cdn.jsdelivr.net/npm/live2dv3@1.1.5/live2dv3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/live2dv3@1.1.6/live2dv3.min.js"></script>
<!-- 加载Live2d模型 -->
<script>
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ <h1>第一次加载较慢,请耐心等待!</h1>
window.onload = () => {
new l2dViewer({
el: document.getElementById('L2dCanvas'),
basePath: 'https://cdn.jsdelivr.net/npm/live2dv3@1.1.5/assets',
basePath: 'https://cdn.jsdelivr.net/npm/live2dv3@1.1.6/assets',
modelName: 'biaoqiang_3',
width: 500,
height: 300,
sizeLimit: false,
mobileLimit: false,
sounds: [
'sounds/demo.mp3',
'https://cdn.jsdelivr.net/npm/live2dv3@1.1.5/assets/biaoqiang_3/sounds/demo.mp3'
'https://cdn.jsdelivr.net/npm/live2dv3@1.1.6/assets/biaoqiang_3/sounds/demo.mp3'
]
})
}
Expand Down
22 changes: 11 additions & 11 deletions live2dv3.js
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,16 @@ class l2dViewer { // eslint-disable-line no-unused-vars
const currentMotion = bodyMotions[Math.floor(Math.random() * bodyMotions.length)]
this.startAnimation(currentMotion, 'base')
}
if (sounds && sounds.length > 0) this.playAudio(sounds[Math.floor((Math.random() * sounds.length))])
if (sounds && sounds.length > 0) {
const soundFile = sounds[Math.floor((Math.random() * sounds.length))]
const filePath = /^https?:\/\//.test(soundFile) ? soundFile : [basePath, modelName, soundFile].join('/').replace(/\/\//g, '/')
try {
new Audio(filePath).play()
} catch (e) {
console.error('Sound playback failed:', e)
}
this.playAudio()
}
}

this.isClick = false
Expand Down Expand Up @@ -1839,15 +1848,6 @@ class l2dViewer { // eslint-disable-line no-unused-vars
return ((left <= tx) && (tx <= right) && (top <= ty) && (ty <= bottom))
}

playAudio (file) {
const filePath = /^https?:\/\//.test(file) ? file : (this.l2d.loader.baseUrl + '/' + file)
try {
new Audio(filePath).play()
} catch (e) {
console.error('Sound playback failed:', e)
}
}

isDom (e) {
if (typeof HTMLElement === 'object') {
return e instanceof HTMLElement
Expand All @@ -1856,7 +1856,7 @@ class l2dViewer { // eslint-disable-line no-unused-vars
}
}
}
const VERSION = '1.1.5'
const VERSION = '1.1.6'
function sayHello () {
var _a
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "live2dv3",
"version": "1.1.5",
"version": "1.1.6",
"description": "在网页上添加 moc3 格式的Live2d模型 https://live2dv3demo.hclonely.com/",
"main": "live2dv3.js",
"scripts": {
Expand Down

0 comments on commit 084552c

Please sign in to comment.