Skip to content
This repository has been archived by the owner on May 7, 2022. It is now read-only.

Commit

Permalink
Add button to stop playing sound
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzi committed Sep 17, 2018
1 parent 15dfa6f commit 6ede773
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions src/renderer/components/LandingPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
label="Actions" width="160">
<template slot-scope="scope">
<el-button
v-if="scope.row.audio !== null"
size="mini"
icon="el-icon-loading"
type="success"
@click="playSound(scope.$index, scope.row)"></el-button>
<el-button
v-else
size="mini"
icon="el-icon-caret-right"
@click="playSound(scope.$index, scope.row)"></el-button>
Expand Down Expand Up @@ -72,7 +79,12 @@
},
methods: {
addSound (event) {
var file = { name: event.target.files[0].name, path: event.target.files[0].path, key: null }
var file = {
name: event.target.files[0].name,
path: event.target.files[0].path,
key: null,
audio: null
}
this.tableData.push(file)
this.$refs.selectFile.value = null
Expand All @@ -81,11 +93,30 @@
playSound (index, row) {
if (this.dialogVisible || !this.active) return
var audio = new Audio(this.tableData[index].path)
audio.play()
// if the sound is playing stop it
if (this.tableData[index].audio !== null) {
this.tableData[index].audio.pause()
this.tableData[index].audio = null
return
}
this.tableData[index].audio = new Audio(this.tableData[index].path)
this.tableData[index].audio.onended = () => {
this.tableData[index].audio = null
}
this.tableData[index].audio.play()
},
removeSound (index, row) {
this.$electron.ipcRenderer.send('streamersb:unregister:shortcut', { accelerator: this.tableData[index].key })
// if the sound is playing stop it
if (this.tableData[index].audio !== null) {
this.tableData[index].audio.pause()
this.tableData[index].audio = null
}
// if the sound has a key, unregister it
if (this.tableData[index].key !== null) {
this.$electron.ipcRenderer.send('streamersb:unregister:shortcut', { accelerator: this.tableData[index].key })
}
this.tableData = this.tableData.filter((file, i) => i !== index)
this.saveChanges()
Expand Down

0 comments on commit 6ede773

Please sign in to comment.