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

Generalise media browse dialog from media player #7467

Closed

Conversation

rob-mccann
Copy link
Contributor

Allows other components and custom components to prompt for users to select an item from the library.

I'm new to HA and feeling my way through the codebase so please do take a good look and let me know if it makes sense!

Proposed change

Use case: I'd like to build a custom(?) card that launches a specific xbox game without having to find the content IDs.

The idea is to trigger this component from a new input type in the card configuration UI to fill the config.

Moving it to an event driven form means decouples it from the media player and allows it to be called from anywhere, including custom cards in the future.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

@homeassistant
Copy link
Contributor

Hi @rob-mccann,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

import { computeRTLDirection } from "../../common/util/compute_rtl";
import { debounce } from "../../common/util/debounce";
import type { MediaPlayerItem } from "../../data/media-player";
import { fireEvent } from "../common/dom/fire_event";
Copy link
Member

Choose a reason for hiding this comment

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

Why did you move all these files?

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 moved the dialog-related items to the dialog folder which left no need for the additional media-player directory in components so I moved ha-media-player-browse.ts up a level.

Copy link
Member

Choose a reason for hiding this comment

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

But why? The media browser is related to the media player, so it makes sense to have it all together there?

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 idea is to allow the media browser to be used outside of the media player - for example, in a card editor to select media content. I don't feel too strongly about this though as it'll work for this usecase irrespective of location :)

fireEvent(element, "show-dialog", {
dialogTag: "dialog-media-player-browse",
dialogImport: () =>
import(
/* webpackChunkName: "dialog-media-player-browse" */ "./dialog-media-player-browse"
),
dialogParams,
});
fireEvent(element, "hass-media-browse", dialogParams);
Copy link
Member

Choose a reason for hiding this comment

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

The media browser dialog should be lazy-loaded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bramkragten
Copy link
Member

Not sure I understand what you are trying to do here, I think all you want is already there. The only thing you can't do right now is import the dialog.

But if it is imported (so after you triggered it from the normal UI), you should be able to use:

fireEvent(element, "show-dialog", {
    dialogTag: "dialog-media-player-browse",
    dialogParams,
  });

@rob-mccann
Copy link
Contributor Author

@bramkragten I'm trying to launch the browser from a different, custom card - there's no guarantee that it has previously been triggered.

@rob-mccann
Copy link
Contributor Author

rob-mccann commented Oct 23, 2020 via email

@bramkragten
Copy link
Member

I still don't understand what you want to do with the dialog, but this should not be a mixin and should just be handled by the normal dialog logic.

@rob-mccann
Copy link
Contributor Author

I wish to create a new card in lovelace.
The card will display media images.
Clicking the image will launch the media on a media player entity.

Now - this card can be configured via YAML but I'd rather provide a UI that allows the user to select the media to show on the card via the media browser. Hope that makes sense?

@rob-mccann
Copy link
Contributor Author

@bramkragten I've refactored the PR based on your feedback - do let me know if I've put all this in the right place - notably the mixin.

@bramkragten
Copy link
Member

This is not the way we handle dialogs, you used the deprecated old way. We also are not going to make our code much more complicated to support custom cards. I'm going to close this.

@1ntroduc3
Copy link

This is really something we'd like to have. this way we can call the mediabrowser card in a popup for a specific media player. Please reconsider @bramkragten

@Clooos
Copy link

Clooos commented May 27, 2021

Hi, I really want to be able to call the media browser popup from a button, I don't use the default media player and I don't use the sidebar, is there any chance that you will reconsider this @bramkragten ? I have searched a lot for this and we are many who really need that feature 🙏 Thanks a lot in advance 😀

@realroywalker
Copy link

@rob-mccann Did you ever manage to achieve launching the media browser via a custom button/card ? - I'm trying to do the same and have been searching for days but no luck.
I really don't want to have the full media player present on my dashboard just to make use of the media browser button, so keen to hear if you found a solution!

@rob-mccann
Copy link
Contributor Author

@rob-mccann Did you ever manage to achieve launching the media browser via a custom button/card ?

Unfortunately, I didn't make any more progress after the MR was closed. Apologies!

@github-actions github-actions bot locked and limited conversation to collaborators Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to fire the media browser from any card as an action
7 participants