mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add Media Browser support to VLC (#72052)
This commit is contained in:
parent
14361f9587
commit
12020ffac1
@ -6,11 +6,16 @@ import logging
|
|||||||
import vlc
|
import vlc
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.components import media_source
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
|
BrowseMedia,
|
||||||
MediaPlayerEntity,
|
MediaPlayerEntity,
|
||||||
MediaPlayerEntityFeature,
|
MediaPlayerEntityFeature,
|
||||||
)
|
)
|
||||||
|
from homeassistant.components.media_player.browse_media import (
|
||||||
|
async_process_play_media_url,
|
||||||
|
)
|
||||||
from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC
|
from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC
|
||||||
from homeassistant.const import CONF_NAME, STATE_IDLE, STATE_PAUSED, STATE_PLAYING
|
from homeassistant.const import CONF_NAME, STATE_IDLE, STATE_PAUSED, STATE_PLAYING
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -54,6 +59,7 @@ class VlcDevice(MediaPlayerEntity):
|
|||||||
| MediaPlayerEntityFeature.PLAY_MEDIA
|
| MediaPlayerEntityFeature.PLAY_MEDIA
|
||||||
| MediaPlayerEntityFeature.PLAY
|
| MediaPlayerEntityFeature.PLAY
|
||||||
| MediaPlayerEntityFeature.STOP
|
| MediaPlayerEntityFeature.STOP
|
||||||
|
| MediaPlayerEntityFeature.BROWSE_MEDIA
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, name, arguments):
|
def __init__(self, name, arguments):
|
||||||
@ -158,15 +164,36 @@ class VlcDevice(MediaPlayerEntity):
|
|||||||
self._vlc.stop()
|
self._vlc.stop()
|
||||||
self._state = STATE_IDLE
|
self._state = STATE_IDLE
|
||||||
|
|
||||||
def play_media(self, media_type, media_id, **kwargs):
|
async def async_play_media(self, media_type, media_id, **kwargs):
|
||||||
"""Play media from a URL or file."""
|
"""Play media from a URL or file."""
|
||||||
if media_type != MEDIA_TYPE_MUSIC:
|
# Handle media_source
|
||||||
|
if media_source.is_media_source_id(media_id):
|
||||||
|
sourced_media = await media_source.async_resolve_media(self.hass, media_id)
|
||||||
|
media_id = sourced_media.url
|
||||||
|
|
||||||
|
elif media_type != MEDIA_TYPE_MUSIC:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Invalid media type %s. Only %s is supported",
|
"Invalid media type %s. Only %s is supported",
|
||||||
media_type,
|
media_type,
|
||||||
MEDIA_TYPE_MUSIC,
|
MEDIA_TYPE_MUSIC,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
self._vlc.set_media(self._instance.media_new(media_id))
|
|
||||||
self._vlc.play()
|
media_id = async_process_play_media_url(self.hass, media_id)
|
||||||
|
|
||||||
|
def play():
|
||||||
|
self._vlc.set_media(self._instance.media_new(media_id))
|
||||||
|
self._vlc.play()
|
||||||
|
|
||||||
|
await self.hass.async_add_executor_job(play)
|
||||||
self._state = STATE_PLAYING
|
self._state = STATE_PLAYING
|
||||||
|
|
||||||
|
async def async_browse_media(
|
||||||
|
self, media_content_type=None, media_content_id=None
|
||||||
|
) -> BrowseMedia:
|
||||||
|
"""Implement the websocket media browsing helper."""
|
||||||
|
return await media_source.async_browse_media(
|
||||||
|
self.hass,
|
||||||
|
media_content_id,
|
||||||
|
content_filter=lambda item: item.media_content_type.startswith("audio/"),
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user