def setUp(self): self.playerInfo = PlayerInfo() self.playerInfo.set_provider('yly', 'http://uri-logo.com') self.playerInfo.set_provider_name('yyy-second') self.playerInfo.set_lyric('http://uri-lrc.com') self.playerInfo.set_art('art') self.playerInfo.set_title('title') self.playerInfo.set_title_subtext1('sub text1') self.playerInfo.set_title_subtext2('sub text2') self.playerInfo.set_audio_item_type(PlayerInfoAudioItemEnum.FORMAT_LRC) self.playerInfo.set_media_length_in_ms(12321.232) favoriteButton = FavoriteButton() favoriteButton.set_enabled(False) self.playerInfo.add_control(favoriteButton) showPlayListButton = ShowPlayListButton() showPlayListButton.set_selected(True) self.playerInfo.set_controls(showPlayListButton) showFavoriteListButton = ShowFavoriteListButton() repeatButton = RepeatButton(RepeatButtonEnum.REPEAT_ONE) self.playerInfo.set_controls([showFavoriteListButton, repeatButton])
def audioPlay(self): ''' 播放指令 ''' directives = [] directive1 = Play( 'http://audio.xmcdn.com/group27/M07/91/30/wKgJW1kVpTTysDS9ABG_opoNMoA008.m4a', PlayBehaviorEnum.REPLACE_ALL) playerInfo = PlayerInfo() playerInfo.set_title('Python') playerInfo.set_title_subtext1('python') playerInfo.set_art( 'https://imagev2.xmcdn.com/group26/M03/94/DD/wKgJWFkVpOyzKhU_AABPh3rraa8772.jpg!op_type=5&upload_type=cover&device_type=ios&name=web_meduim&strip=0&quality=7' ) playpause = PlayPauseButton() previous = PreviousButton() next = NextButton() showPlayList = ShowPlayListButton() showPlayList.set_enabled(False) controls = [playpause, previous, next, showPlayList] # controls = [playpause, previous] playerInfo.set_controls(controls) # playerInfo.add_control(NextButton()) directive1.set_player_info(playerInfo) # directive2 = Play('http://audio.xmcdn.com/group27/M04/91/28/wKgJW1kVpMfRrzE5AAzyjIkEf9s698.m4a', PlayBehaviorEnum.ENQUEUE) # playerInfo = PlayerInfo() # playerInfo.set_title('子夜吴歌') # playerInfo.set_art( # 'https://imagev2.xmcdn.com/group26/M03/94/DD/wKgJWFkVpOyzKhU_AABPh3rraa8772.jpg!op_type=5&upload_type=cover&device_type=ios&name=web_meduim&strip=0&quality=7') # playpause = PlayPauseButton() # previous = PreviousButton() # previous.set_selected(True) # controls = [playpause, previous] # playerInfo.set_controls(controls) # playerInfo.add_control(NextButton()) # directive2.set_player_info(playerInfo) # directive3 = Play('http://audio.xmcdn.com/group27/M04/91/28/wKgJW1kVpMfRrzE5AAzyjIkEf9s698.m4a', PlayBehaviorEnum.ENQUEUE) # # playerInfo = PlayerInfo() # playerInfo.set_title('子夜吴歌') # playerInfo.set_art( # 'https://imagev2.xmcdn.com/group26/M03/94/DD/wKgJWFkVpOyzKhU_AABPh3rraa8772.jpg!op_type=5&upload_type=cover&device_type=ios&name=web_meduim&strip=0&quality=7') # playpause = PlayPauseButton() # previous = PreviousButton() # previous.set_selected(True) # controls = [playpause, previous] # playerInfo.set_controls(controls) # playerInfo.add_control(NextButton()) # directive3.set_player_info(playerInfo) directives.append(directive1) # directives.append(directive2) # directives.append(directive3) return {'directives': directives, 'outputSpeech': r'正在为你播放歌曲'}
def getAnimalResponse(self, animal): name = Utils.getName(animal) content = Utils.getDescribtion(animal) imgUrl = Utils.getImageUrl(animal) soundUrl = Utils.getSoundUrl(animal) self.set_session_attribute('name', name, None) play = Play(soundUrl, PlayBehaviorEnum.REPLACE_ALL) playerInfo = PlayerInfo() playpause = PlayPauseButton() previous = PreviousButton() next = NextButton() previous.set_selected(True) controls = [previous, playpause, next] playerInfo.set_controls(controls) playerInfo.set_title(name) playerInfo.set_title_subtext1(content) playerInfo.set_art(imgUrl) play.set_player_info(playerInfo) template = BodyTemplate3() template.set_title(name) template.set_plain_content(content) template.set_image(Utils.getImageUrl(animal)) template.set_background_image(Utils.getImageUrl(animal)) renderTemplate = RenderTemplate(template) outputSpeech = name return { 'directives': [play], 'reprompt': content, 'outputSpeech': outputSpeech }
:return: ''' if StreamFormatEnum.inEnum(streamFormat): self.data['audioItem']['stream'][ 'streamFormat'] = streamFormat.value else: self.data['audioItem']['stream'][ 'streamFormat'] = StreamFormatEnum.STREAM_FORMAT_MP3.value return self if __name__ == '__main__': directive = Play('http://www.baidu.com') directive.setStreamFormat('AUDIO_M3U8') playerInfo = PlayerInfo() # 创建暂停按钮 playpause = PlayPauseButton() previous = PreviousButton() previous.setSelected(True) controls = [playpause, previous] playerInfo.setControls(controls) playerInfo.addControl(NextButoon()) playerInfo.setTitle('周杰伦') playerInfo.setTitleSubtext1('七里香') playerInfo.setArt('http://adfadfa') # 设置Play指令的PlayerInfo directive.setPlayerInfo(playerInfo)
:return: ''' if StreamFormatEnum.inEnum(stream_format): self.data['audioItem']['stream'][ 'streamFormat'] = stream_format.value else: self.data['audioItem']['stream'][ 'streamFormat'] = StreamFormatEnum.STREAM_FORMAT_MP3.value return self if __name__ == '__main__': directive = Play('http://www.baidu.com') directive.set_stream_format('AUDIO_M3U8') playerInfo = PlayerInfo() # 创建暂停按钮 playpause = PlayPauseButton() previous = PreviousButton() previous.set_selected(True) controls = [playpause, previous] playerInfo.set_controls(controls) playerInfo.set_controls(NextButton()) playerInfo.set_title('周杰伦') playerInfo.set_title_subtext1('七里香') playerInfo.set_art('http://adfadfa') # 设置Play指令的PlayerInfo directive.set_player_info(playerInfo)
class PlayerInfoTest(unittest.TestCase): def setUp(self): self.playerInfo = PlayerInfo() self.playerInfo.set_provider('yly', 'http://uri-logo.com') self.playerInfo.set_lyric('http://uri-lrc.com') self.playerInfo.set_art('art') self.playerInfo.set_title('title') self.playerInfo.set_title_subtext1('sub text1') self.playerInfo.set_title_subtext2('sub text2') self.playerInfo.set_audio_item_type(AudioItemTypeEnum.FORMAT_LRC) self.playerInfo.set_media_length_in_ms(12321.232) favoriteButton = FavoriteButton() favoriteButton.set_enabled(False) self.playerInfo.add_control(favoriteButton) showPlayListButton = ShowPlayListButton() showPlayListButton.set_selected(True) self.playerInfo.set_controls(showPlayListButton) showFavoriteListButton = ShowFavoriteListButton() repeatButton = RepeatButton(RepeatButtonEnum.REPEAT_ONE) self.playerInfo.set_controls([showFavoriteListButton, repeatButton]) def testGetData(self): ret = { 'content': { 'audioItemType': 'LRC', 'mediaLengthInMilliseconds': 12321, 'provider': { 'name': 'yly', 'logo': { 'src': 'http://uri-logo.com' } }, 'lyric': { 'url': 'http://uri-lrc.com', 'format': 'LRC' }, 'art': { 'src': 'art' }, 'title': 'title', 'titleSubtext1': 'sub text1', 'titleSubtext2': 'sub text2' }, 'controls': [{ 'type': 'BUTTON', 'name': 'FAVORITE', 'enabled': False, 'selected': False }, { 'type': 'BUTTON', 'name': 'SHOW_PLAYLIST', 'enabled': True, 'selected': True }, { 'type': 'BUTTON', 'name': 'SHOW_FAVORITE_LIST', 'enabled': True, 'selected': False }, { 'type': 'RADIO_BUTTON', 'name': 'REPEAT', 'selectedValue': 'REPEAT_ONE' }] } data = self.playerInfo.get_data() self.assertEqual(data, ret) pass