''' if StreamFormatEnum.inEnum(stream_format): self.data['audioItem']['stream']['streamFormat'] = stream_format else: self.data['audioItem']['stream'][ 'streamFormat'] = StreamFormatEnum.STREAM_FORMAT_MP3 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.add_control(NextButton()) playerInfo.set_title('周杰伦') playerInfo.set_title_subtext1('七里香') playerInfo.set_art('http://adfadfa') # 设置Play指令的PlayerInfo directive.set_player_info(playerInfo) print(directive.get_data())
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