『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
123
返回列表 发新帖
楼主: qqdwtypm

[经验分享] 小爱音箱dlna+网易云音乐插件实现自动替换vip歌曲和语音播放

  [复制链接]

25

主题

640

帖子

2913

积分

金牌会员

Rank: 6Rank: 6

积分
2913
金钱
2263
HASS币
40
发表于 2024-1-28 23:26:20 | 显示全部楼层
dlna播放不会一直循环吗
回复

使用道具 举报

1

主题

32

帖子

176

积分

注册会员

Rank: 2

积分
176
金钱
144
HASS币
0
发表于 2024-4-26 16:32:16 | 显示全部楼层
请问楼主,如何屏蔽小爱自动回复的“。。。请先绑定。。。。”的提示语。谢谢。
回复

使用道具 举报

0

主题

15

帖子

70

积分

注册会员

Rank: 2

积分
70
金钱
55
HASS币
0
发表于 2024-4-28 20:59:54 | 显示全部楼层
感谢分享,学习了
回复

使用道具 举报

0

主题

4

帖子

46

积分

新手上路

Rank: 1

积分
46
金钱
42
HASS币
0
发表于 2024-5-28 19:57:26 | 显示全部楼层
需要的内容,先收藏
回复

使用道具 举报

0

主题

29

帖子

514

积分

高级会员

Rank: 4

积分
514
金钱
485
HASS币
0
发表于 2024-8-24 12:10:00 | 显示全部楼层
使用云音乐新版修改后10秒钟就直接下一首歌曲了,楼主还能修复一下不,感谢
回复

使用道具 举报

10

主题

106

帖子

1289

积分

金牌会员

Rank: 6Rank: 6

积分
1289
金钱
1183
HASS币
0
发表于 2024-10-30 20:13:41 | 显示全部楼层
一直单曲循环怎么办,改完代码也无效..
回复

使用道具 举报

0

主题

3

帖子

50

积分

注册会员

Rank: 2

积分
50
金钱
47
HASS币
0
发表于 2024-11-28 07:35:49 | 显示全部楼层
本帖最后由 ha_wr5v8k 于 2024-11-28 07:40 编辑
    ### 参考https://bbs.hassbian.com/thread-22469-3-1.html
    ### self.before_state 小爱音箱播放器上次播放进度与上上次状态;self._attr_media_* 小爱音箱播放器当前播放进度;self.current_state 小爱音箱播放器上次状态;media_player.state 小爱音箱播放器当前状态;self._attr_state 云音乐播放器当前状态
    def interval(self, now):
        # 暂停时不更新
        if self._attr_state == STATE_PAUSED:
            return

        media_player = self.media_player
        if media_player is not None:
            attrs = media_player.attributes
            self._attr_media_position = attrs.get('media_position', 0)
            self._attr_media_duration = attrs.get('media_duration', 0)
            self._attr_media_position_updated_at = datetime.datetime.now()
            # 判断是否下一曲
            if self.before_state is not None:
                # 判断音乐总时长
                # if self.before_state['media_duration'] > 0 and self.before_state['media_duration'] - self.before_state['media_position'] <= 5:
                    # 判断源音乐播放器状态
                    # if self.before_state['state'] == STATE_PLAYING and self.current_state == STATE_IDLE:
                        # self.hass.create_task(self.async_media_next_track())
                        # self.before_state = None
                        # return
                ### 判断音乐总时长,但小爱音箱播放器更新间隔是二十二秒
                import asyncio
                if (self.before_state['media_duration'] > 0 and self.before_state['media_duration'] - self.before_state['media_position'] <= 22) or 'next_at' in self.before_state:
                    if ('next_at' not in self.before_state):
                        self.before_state['next_at'] = datetime.timedelta(seconds=max(self.before_state['media_duration'] - self.before_state['media_position'] - 5, 0)) + self._attr_media_position_updated_at
                    if (self._attr_media_position_updated_at >= self.before_state['next_at']):
                        # 判断源音乐播放器状态(空闲则下一首),但小爱音箱播放器状态是循环播放
                        if self.before_state['state'] == STATE_PLAYING and (self.current_state == STATE_IDLE or self.current_state == STATE_PLAYING):
                            asyncio.run_coroutine_threadsafe(self.async_media_next_track(), self.hass.loop)
                            self.before_state = None
                            return
                        else:
                            del self.before_state['next_at']

                # 源播放器空闲 & 当前正在播放
                # if self.before_state['media_duration'] == 0 and self.before_state['media_position'] == 0 and self.current_state == STATE_IDLE \
                    # and self._attr_media_duration == 0 and self._attr_media_position == 0 and self._attr_state == STATE_PLAYING:
                        # self.hass.create_task(self.async_media_next_track())
                        # self.before_state = None
                        # return
                ### 源播放器空闲 & 当前正在播放(空闲首次播放则下一首),但小爱音箱播放器状态是空闲暂停和缓冲暂停
                if (self.before_state['media_duration'] == 0 and self.before_state['media_position'] == 0 and (self.current_state == STATE_IDLE or self.current_state == STATE_PAUSED) \
                    and self._attr_media_duration == 0 and self._attr_media_position == 0 and self._attr_state == STATE_PLAYING) or 'next_at' in self.before_state:
                      if ('next_at' not in self.before_state):
                          self.before_state['next_at'] = datetime.timedelta(seconds=22) + self._attr_media_position_updated_at
                      if (self._attr_media_position_updated_at >= self.before_state['next_at']):
                          if self.before_state['media_duration'] == 0 and self.before_state['media_position'] == 0 and (self.current_state == STATE_IDLE or media_player.state == STATE_PAUSED) \
                              and media_player.attributes.get('media_duration', 0) == 0 and self._attr_state == STATE_PLAYING:
                                  asyncio.run_coroutine_threadsafe(self.async_media_next_track(), self.hass.loop)
                                  self.before_state = None
                                  return
                          else:
                              del self.before_state['next_at']

                ### 小爱音箱播放器暂停 & 当前正在播放
                if (self.before_state['media_duration'] == 0 and self.before_state['media_position'] == 0 and self.current_state == STATE_PAUSED \
                    and self._attr_media_duration > 0 and self._attr_media_position > 0 and self._attr_state == STATE_PLAYING) or 'pause_at' in self.before_state:
                    if ('pause_at' not in self.before_state):
                        self.before_state['pause_at'] = datetime.timedelta(seconds=22) + self._attr_media_position_updated_at
                    if (self._attr_media_position_updated_at >= self.before_state['pause_at']):
                        if media_player.state == STATE_PAUSED and self._attr_state ==  STATE_PLAYING:
                            asyncio.run_coroutine_threadsafe(self.async_media_pause(), self.hass.loop)
                            self.before_state = None
                            return
                        else:
                            del self.before_state['pause_at']

            self.before_state = {
                'media_position': int(self._attr_media_position),
                'media_duration': int(self._attr_media_duration),
                'state': self.current_state
            }
            self.current_state = media_player.state

        if hasattr(self, 'playlist'):
            music_info = self.playlist[self.playindex]
            self._attr_app_name = music_info.singer
            self._attr_media_image_url = music_info.thumbnail
            self._attr_media_album_name = music_info.album
            self._attr_media_title = music_info.song
            self._attr_media_artist = music_info.singer

回复

使用道具 举报

0

主题

29

帖子

514

积分

高级会员

Rank: 4

积分
514
金钱
485
HASS币
0
发表于 2024-12-5 23:35:07 | 显示全部楼层

好像还是不行,
回复

使用道具 举报

0

主题

3

帖子

50

积分

注册会员

Rank: 2

积分
50
金钱
47
HASS币
0
发表于 2024-12-13 20:37:01 | 显示全部楼层
本帖最后由 ha_wr5v8k 于 2024-12-13 20:38 编辑
a431115 发表于 2024-12-5 23:35
好像还是不行,

我只是把延迟的阻塞替换成时间差判断,如果你一直切歌,可能是判断小爱音箱播放器更新间隔二十二秒不够大,需要设大,或者你的集成没办法获取到设备的播放状态?
回复

使用道具 举报

0

主题

8

帖子

47

积分

新手上路

Rank: 1

积分
47
金钱
39
HASS币
0
发表于 7 天前 | 显示全部楼层
先收藏,再学习
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-23 23:59 , Processed in 0.052119 second(s), 29 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表