dev-audioprocessing/pages/index.vue

157 lines
4.7 KiB
Vue
Raw Permalink Normal View History

2022-12-11 23:33:34 +00:00
<template>
2022-12-23 14:42:30 +00:00
<div>
2023-03-07 04:28:32 +00:00
<div class="container-fluid" style="background-image: url('/images/posters/poster2.png');background-size: cover">
2022-12-31 20:29:52 +00:00
<div class="row">
2023-01-01 19:18:13 +00:00
<div class="col-12 px-0 mx-0">
2023-01-27 03:33:29 +00:00
<audio ref="audio" src="/sounds/Lagoon.aac" loop></audio>
2023-01-01 18:40:22 +00:00
<video-background
2023-02-27 20:32:41 +00:00
preload="auto"
2023-06-11 19:20:39 +00:00
poster="/images/poster.png"
2023-02-25 06:48:20 +00:00
src="/video/bg-video.mp4"
2023-01-01 19:18:13 +00:00
style=" height: 100vh;"
2023-01-01 18:40:22 +00:00
>
2023-01-02 23:19:42 +00:00
2023-01-27 03:33:29 +00:00
<home-bar v-on:play="playPause" :title="title" />
2023-01-02 23:19:42 +00:00
2023-01-01 19:18:13 +00:00
<div class="container-fluid">
2023-01-02 23:19:42 +00:00
<div class="row justify-content-center">
2023-06-11 19:20:39 +00:00
<div class="adaptive pb-3">
2023-01-02 23:19:42 +00:00
2023-01-01 19:18:13 +00:00
<div class="col-12 ">
2023-01-03 22:38:43 +00:00
<div class="d-none d-md-block mx-auto pb-1" style="width: 225px" >
<div class="progress " style="height: 10px">
2023-06-11 19:20:39 +00:00
<div class="progress-bar bar" role="progressbar" aria-label="Basic example" :style="{width:bar_width+'%'}" style="background-color: #e9c046;transition: 0.1s" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
2023-01-03 22:38:43 +00:00
</div>
</div>
2023-01-02 23:19:42 +00:00
<div class="d-flex justify-content-center mb-1">
2023-02-25 06:48:20 +00:00
<nuxt-link to="#adaptive-modal" data-bs-target="#adaptive-modal" data-bs-toggle="modal" class="text-muted text-decoration-none fw-bold fs-6 ">{{t('adaptive_soundscap')}} : <span class="" style="color: #e9c046">On</span> </nuxt-link><span class="ps-3"><i style="padding: 5px 0px;" class="fa-solid text-muted d-flex fa-chevron-right"></i></span>
2023-01-01 19:18:13 +00:00
</div>
2023-01-03 22:38:43 +00:00
<div class="d-block d-md-none mx-auto pb-1" style="width: 225px" >
2023-01-02 23:19:42 +00:00
<div class="progress " style="height: 10px">
2023-06-11 19:20:39 +00:00
<div class="progress-bar bar" role="progressbar" aria-label="Basic example" :style="{width:bar_width+'%'}" style="background-color: #e9c046;transition: 0.1s" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
2023-01-02 23:19:42 +00:00
</div>
</div>
2023-01-01 19:18:13 +00:00
</div>
2023-02-25 06:48:20 +00:00
<BootomBar/>
2023-01-02 23:19:42 +00:00
</div>
2023-01-01 19:18:13 +00:00
</div>
</div>
2023-01-01 18:40:22 +00:00
</video-background>
<!-- <video muted id="myVideo" autoplay loop>-->
<!-- <source src="~/assets/video/bg-video.mp4" type="video/mp4">-->
<!-- <source src="~/assets/video/bg-video.ogg" type="video/ogg">-->
<!-- Your browser does not support HTML5 video.-->
<!-- </video>-->
2022-12-31 20:29:52 +00:00
</div>
</div>
</div>
2023-01-01 19:18:13 +00:00
2022-12-23 14:42:30 +00:00
</div>
2022-12-12 03:10:34 +00:00
</template>
2022-12-23 14:42:30 +00:00
<script>
2022-12-24 16:36:24 +00:00
2022-12-23 14:42:30 +00:00
import HomeBar from "../components/homebar";
2023-02-25 06:48:20 +00:00
import BootomBar from "~/components/BootomBar.vue";
2022-12-23 14:42:30 +00:00
export default {
2023-02-25 06:48:20 +00:00
setup() {
2023-03-05 16:37:21 +00:00
definePageMeta({
middleware: 'auth'
})
2023-02-25 06:48:20 +00:00
const { t } = useI18n()
const localePath = useLocalePath()
return {
t,
localePath,
}
},
2023-06-11 19:20:39 +00:00
mounted() {
navigator.mediaDevices.getUserMedia({audio: true})
.then((stream)=> {
var audioCtx = new AudioContext();
var source = audioCtx.createMediaStreamSource(stream);
this.analyser = audioCtx.createAnalyser();
source.connect(this.analyser);
this.analyser.fftSize = 2048;
var bufferLength = this.analyser.frequencyBinCount;
this.dataArray = new Uint8Array(bufferLength);
this.updateMeter();
})
.catch(function(err) {
console.log('Error accessing microphone', err);
});
},
2023-02-25 06:48:20 +00:00
components: {BootomBar, HomeBar},
2023-01-02 23:19:42 +00:00
data(){
return{
2023-01-03 00:59:50 +00:00
title:'Lagoon soundscape',
2023-06-11 19:20:39 +00:00
bar_width:0,
analyser:null,
dataArray:null,
2023-01-02 23:19:42 +00:00
}
},
2022-12-28 00:20:42 +00:00
methods:{
handleAnimation: function (anim) {
this.anim = anim;
2023-01-27 03:33:29 +00:00
},
2023-06-11 19:20:39 +00:00
updateMeter(){
requestAnimationFrame(this.updateMeter);
this.analyser.getByteFrequencyData(this.dataArray);
var rms = this.getRMS(this.dataArray);
var level = 20 * Math.log10(rms / 128);
level = Math.max(0, Math.min(100, level + 100));
// bar.style.width = level + '%';
this.bar_width=level;
},
getRMS(dataArray) {
var rms = 0;
for (var i = 0; i < dataArray.length; i++) {
rms += dataArray[i] * dataArray[i];
}
rms /= dataArray.length;
rms = Math.sqrt(rms);
return rms;
},
2023-01-27 03:33:29 +00:00
playPause(play){
console.log("Play Pause");
if (play){
this.$refs['audio'].play();
}else {
this.$refs['audio'].pause();
}
2022-12-28 00:20:42 +00:00
}
}
2022-12-31 20:05:12 +00:00
2022-12-23 14:42:30 +00:00
}
2022-12-31 20:05:12 +00:00
</script>
<style>
#myVideo{
position: fixed;
right: 0;
bottom: 0;
2023-01-01 18:33:52 +00:00
min-width: 100%;
2022-12-31 20:05:12 +00:00
padding: 0;
margin: 0;
z-index: -99;
}
.adaptive{
position: fixed;
bottom: 0;
text-align: center;
width: 100%;
}
</style>