Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualizer not visualizing audio with a url #124

Open
roseaneesha opened this issue Dec 18, 2022 · 7 comments
Open

Visualizer not visualizing audio with a url #124

roseaneesha opened this issue Dec 18, 2022 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@roseaneesha
Copy link

roseaneesha commented Dec 18, 2022

The audio plays, but the visualizer doesn't seem to show the waves.
This only happens if the source audio is a url (eg:https://www.soundjay.com/human/sounds/heartbeat-01a.mp3)
Works perfectly if the audio is added as a file in the local system

Screenshot_20221218_210258

@staskobzar
Copy link
Owner

It is blocked by CORS policy. I will work on the patch.
Thanks for the reports

@staskobzar staskobzar self-assigned this Dec 18, 2022
@staskobzar staskobzar added the bug Something isn't working label Dec 18, 2022
staskobzar added a commit that referenced this issue Dec 27, 2022
@staskobzar
Copy link
Owner

@roseaneesha I have made some improvements in the module to make sure CORS is enabled during fetch.
But the main problem you have is that you source is not returning "Access-Control-Allow-Origin" header, thus restricting access to the source from ajax requests

@clemenceroumy
Copy link

clemenceroumy commented Oct 9, 2023

👋🏻 Hello @staskobzar, I still have trouble using the component with a spotify url source audio (ex: https://p.scdn.co/mp3-preview/805bbe52bc7f8412e9027579787251375e6b847d?cid=11381bbca5f3479f9462199118c15ad9), having an error MediaElementAudioSource outputs zeroes due to CORS access restrictions for https://p.scdn.co/mp3-preview... in the console
Is there any way to make this work ?

@staskobzar
Copy link
Owner

Hello @clemenceroumy
CORS access controll can be set with "" element attribute "crossorigin".
When you use high level interface functions like "AVLine(...)" this attribute is not enabled. You can use composable function to build and access your "" element.

To make your link work with AVLine you would do something like that:

<script setup lang="ts">
import { ref } from 'vue'
import { makeLineProps } from '@/composables/useProps'
import { useAVLine } from '@/composables/useAVLine'

const props = defineProps(makeLineProps())
const player = ref(null)
const canvas = ref(null)

const spotifyURL = ref('https://p.scdn.co/mp3-preview/805bbe52bc7f8412e9027579787251375e6b847d?cid=11381bbca5f3479f9462199118c15ad9')

useAVLine(player, canvas, props)
</script>

<template>
  <audio ref="player"
    crossorigin="anonymous"
    :controls="true"
    :src="spotifyURL" />
  <canvas ref="canvas" />
</template>

Note crossorigin value in audio element:
image

Basically, all high level functions use compable function to build plugin. You can check "src/components" folder to see how it works for all the components.

@staskobzar staskobzar reopened this Oct 9, 2023
@clemenceroumy
Copy link

@staskobzar Oh yeah, that works well ! Sorry for the inconveniance and thank you for your quick reply and work :)

@drewjgray
Copy link

@staskobzar do you have a patch for v2.5.0 for use with Vue 2? I am also blocked by CORS using a url. Response headers have CORS enabled but the request is set to no-cors.

@staskobzar
Copy link
Owner

staskobzar commented Oct 16, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants