Skip to content

Commit f60378f

Browse files
committed
#2 #1 Working on the local download, working on removing from list.
1 parent 77634f6 commit f60378f

File tree

3 files changed

+68
-35
lines changed

3 files changed

+68
-35
lines changed

components/RecordingItem.vue

+36-27
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,56 @@
11
<template>
22
<v-list-item :ripple="false">
3+
<div class="mr-5">
4+
<span class="overline mr-1">Recording {{ recording.number }}</span>
5+
</div>
36
<v-list-item-avatar>
47
<v-btn x-large icon @click="toggleAudio">
58
<v-icon v-if="isPlaying">mdi-pause</v-icon>
69
<v-icon v-else>mdi-play</v-icon>
710
</v-btn>
811
</v-list-item-avatar>
9-
<v-list-item-content>
10-
<v-list-item-title class="overline">
11-
Recording {{ index + 1 }}
12-
</v-list-item-title>
12+
<v-list-item-content class="px-5">
1313
<v-slider
14-
:value="progress"
1514
active
1615
color="primary lighten-4"
1716
rounded
18-
inverse-label
19-
:label="`${elapsedTime} / ${totalTime}`"
17+
:value="progress"
18+
:hide-details="true"
2019
@change="seek"
2120
@start="sliderConnected = false"
2221
@end="sliderConnected = true"
2322
/>
2423
</v-list-item-content>
24+
<div class="caption mr-5 ml-3 ">
25+
<span> {{ elapsedTime }} / {{ totalDuration }} </span>
26+
</div>
2527
<v-list-item-action>
26-
<v-btn icon x-small color="primary darken-3">
28+
<v-btn
29+
icon
30+
x-small
31+
color="primary darken-3"
32+
:href="href"
33+
:download="download"
34+
>
2735
<v-icon>mdi-download</v-icon>
2836
</v-btn>
2937
</v-list-item-action>
3038
<v-list-item-action>
31-
<v-btn icon x-small>
39+
<v-btn
40+
icon
41+
x-small
42+
color="primary lighten-3"
43+
@click="$emit('remove-item', recording.id)"
44+
>
3245
<v-icon>mdi-close</v-icon>
3346
</v-btn>
3447
</v-list-item-action>
3548
</v-list-item>
3649
</template>
3750
<script>
38-
function getMMSS(duration) {
39-
let minutes = Math.floor(duration / 60)
40-
let seconds = parseInt(duration, 10) - minutes * 60
51+
function getMMSS(timeInSeconds) {
52+
let minutes = Math.floor(timeInSeconds / 60)
53+
let seconds = parseInt(timeInSeconds, 10) - minutes * 60
4154
4255
if (minutes < 10) {
4356
minutes = '0' + minutes
@@ -55,12 +68,8 @@ export default {
5568
type: Object,
5669
default: () => ({
5770
audio: null,
58-
isPlaying: false
71+
encoding: 'mp3'
5972
})
60-
},
61-
index: {
62-
type: Number,
63-
default: 0
6473
}
6574
},
6675
data() {
@@ -70,21 +79,23 @@ export default {
7079
totalDuration: null,
7180
elapsedTime: `00:00`,
7281
progress: 0,
73-
sliderConnected: true
74-
}
75-
},
76-
computed: {
77-
totalTime() {
78-
return getMMSS(this.totalDuration)
82+
sliderConnected: true,
83+
href: null,
84+
download: ''
7985
}
8086
},
8187
beforeMount() {
8288
this.track = new Audio(this.recording.audio)
8389
90+
this.href = this.recording.audio
91+
this.download = `Recording ${this.recording.number + 1}.${
92+
this.recording.encoding
93+
}`
94+
8495
this.track.addEventListener('loadeddata', () => {
8596
console.log('finished loading')
8697
console.log(this.track.duration)
87-
this.totalDuration = this.track.duration
98+
this.totalDuration = getMMSS(this.track.duration)
8899
})
89100
90101
this.track.addEventListener('ended', () => {
@@ -93,7 +104,7 @@ export default {
93104
})
94105
95106
this.track.addEventListener('timeupdate', (event) => {
96-
const s = parseInt(this.track.currentTime % 60)
107+
const s = parseInt(this.track.currentTime, 10)
97108
this.elapsedTime = getMMSS(s)
98109
99110
if (this.sliderConnected) {
@@ -112,8 +123,6 @@ export default {
112123
},
113124
seek(payload) {
114125
if (typeof payload === 'number') {
115-
console.log('endseeking', payload)
116-
console.log((payload * this.track.duration) / 100)
117126
this.track.currentTime = (payload * this.track.duration) / 100
118127
}
119128
}

components/RecordingsList.vue

+21-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
mandatory
66
@change="$emit('input', selected)"
77
>
8-
<div v-for="(recording, index) in recordings" :key="index">
9-
<recording-item :recording="recording" :index="index"></recording-item>
10-
<v-divider v-show="index != recordings.length - 1" inset></v-divider>
8+
<div v-for="(recording, index) in recordingsInternal" :key="recording.id">
9+
<recording-item
10+
:recording="recording"
11+
@remove-item="remove(recording.id)"
12+
></recording-item>
13+
<v-divider
14+
v-show="index != recordingsInternal.length - 1"
15+
inset
16+
></v-divider>
1117
</div>
1218
</v-list-item-group>
1319
</v-list>
@@ -31,7 +37,18 @@ export default {
3137
},
3238
data() {
3339
return {
34-
selected: this.selectedItem
40+
selected: this.selectedItem,
41+
recordingsInternal: this.recordings
42+
}
43+
},
44+
methods: {
45+
remove(id) {
46+
console.log(id)
47+
const index = this.recordings.findIndex(
48+
(recording) => recording.id === id
49+
)
50+
51+
this.recordingsInternal.splice(index, 1)
3552
}
3653
}
3754
}

pages/index.vue

+11-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<timer :timer-status="timerStatus"></timer>
2929

3030
<recordings-list
31+
v-if="recordings.length"
3132
v-model="selected"
3233
:recordings="recordings"
3334
></recordings-list>
@@ -77,7 +78,8 @@ export default {
7778
audioContext: null,
7879
selected: null,
7980
timerStatus: 'stopped',
80-
recordings: []
81+
recordings: [],
82+
count: 0
8183
}
8284
},
8385
created() {
@@ -131,9 +133,14 @@ export default {
131133
onComplete: (recorder, blob) => {
132134
console.warn('Encoding complete')
133135
const url = URL.createObjectURL(blob)
134-
console.log(blob)
135-
this.recordings.push({ audio: url })
136-
// createDownloadLink(blob, recorder.encoding);
136+
// the url already gives us a unique id, so we might as well use that :D
137+
const id = url.split('3333/')[1]
138+
this.recordings.push({
139+
number: ++this.count,
140+
id,
141+
audio: url,
142+
encoding: ENCODING_TYPE
143+
})
137144
}
138145
})
139146

0 commit comments

Comments
 (0)