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

Add Music visualiser #2040

Closed
wants to merge 8 commits into from
Closed

Conversation

flip-dots
Copy link
Contributor

This adds a music visualiser option when you fullscreen the music player which looks cool as heck.

Since the discussion I have changed the colours, decreased the number of bars, and increased the smoothing value and sample size to make it look better on 60hz monitors. I still recommend playing around with the parameters though.

Link to discussion

Example Screenshot:

Screenshot 2023-06-09 203255

@jellyfin-bot jellyfin-bot added the vue Pull requests that edit or add Vue files label Jun 9, 2023
@@ -1,9 +1,14 @@
<template>
<v-btn
:icon="isFavorite ? IMdiHeart : IMdiHeartOutline"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The play pause button would not be centred in the middle without adding another button. I thought the like button made the most sense to add but to do that I needed to make it resizable otherwise it would be too small. I did that the same way that the other buttons that show on both the minimised media player and the full screen media player do it, but also added a default size to make it backwards compatible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see it now, I think I have figured it out, I wrote this code a while ago so my decision making process isn't super clear anymore but I think the reason why I am using v-if and v-else is because I used the shuffle button as a template which does it that way and I guess I didn't know any better, I'll fix it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this doesn't need its own component, since it's small enough. This button should toggle a ref inside the music playback page

@@ -50,11 +51,17 @@
<time-slider />
</v-row>
<v-row class="justify-center align-center">
<audio-visualise-button size="x-large" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, this button should be at the top right in the app bar, since it's not related to playback at all, it's just aesthetic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it should probably be elsewhere, but I feel that it would be even more out of place in the top right since it would be floating alone, in my mind it would make more sense if there was already something there like a casting button. The placement doesn't bother me that much though, so I don't mind changing it if you want.

Comment on lines 101 to 103
const visualiserContainer =
document.querySelectorAll<HTMLElement>('.visualiser')[0];
const audioElement = document.querySelector<HTMLMediaElement>('audio');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really bad practice at Vue. Besides you don't need this at all.

First of all, the visualizer itself warrants it's own component (unlike the button), where the only element is a canvas. Then, you reference that element by accessing it's ref. More info: https://vuejs.org/guide/essentials/template-refs.html

When that button gets clicked in the music player, you can toggle a boolean ref that toggles this component with v-if. in the onMounted hook, you attach the AudioMotionAnalyzer DOM, while on onBeforeUnmount or onUnmounted you destroy it (you don't right now, which will eventually lead to memory leaks).

For accessing the dom element of the media player, you only need to import it from here. Do note that won't work in development, just in production (as noted here), so you must build the client using npm run build.

With that architecture, you don't need to touch the playerlement store for anything and you'd be good with this with perhaps 50 lines only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the help, I'm aware my code is pretty awful and I really appreciate the guidance, I should be able to get this fixed now I know what to do and how to do it.

@ferferga
Copy link
Member

ferferga commented Jun 9, 2023

@flip-dots You can also wrap the music visualizer alongside swiper in a v-fade-transition component that makes a seamless switch between both!

@flip-dots
Copy link
Contributor Author

@flip-dots You can also wrap the music visualizer alongside swiper in a v-fade-transition component that makes a seamless switch between both!

I tried implementing this but it causes the visualiser and carousel to glitch around during the transition and I don't really know how to fix it. I think it might be something to do with the CSS applying after the transition instead of before or maybe something to do with the generation of the canvas but I'm not sure.

@jellyfin-bot
Copy link

Cloudflare Pages deployment

Latest commit 54846c6
Status 🔄 Deploying...
Preview URL Not available
Type 🔀 Preview

View bot logs

@sonarcloud
Copy link

sonarcloud bot commented Jun 10, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@flip-dots flip-dots closed this Jun 10, 2023
@flip-dots flip-dots deleted the music_visualiser branch June 10, 2023 18:29
@flip-dots flip-dots mentioned this pull request Jun 10, 2023
@flip-dots
Copy link
Contributor Author

So, I accidentally managed to close this pull request and it wont let me reopen it so I made another one. Sorry…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vue Pull requests that edit or add Vue files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants