Added playback of audio and video attachments in toots

This commit is contained in:
Manuel Cortez 2022-11-09 13:07:59 -06:00
parent edbc74262a
commit 59409e61a5
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
2 changed files with 24 additions and 4 deletions

View File

@ -335,10 +335,23 @@ class BaseBuffer(base.Buffer):
def audio(self, url='', *args, **kwargs):
if sound.URLPlayer.player.is_playing():
return sound.URLPlayer.stop_audio()
toot = self.get_item()
if toot == None:
item = self.get_item()
if item == None:
return
pass
urls = utils.get_media_urls(item)
if len(urls) == 1:
url=urls[0]
elif len(urls) > 1:
urls_list = dialogs.urlList.urlList()
urls_list.populate_list(urls)
if urls_list.get_response() == widgetUtils.OK:
url=urls_list.get_string()
if hasattr(urls_list, "destroy"): urls_list.destroy()
if url != '':
# try:
sound.URLPlayer.play(url, self.session.settings["sound"]["volume"])
# except:
# log.error("Exception while executing audio method.")
def url(self, url='', announce=True, *args, **kwargs):
if url == '':

View File

@ -34,3 +34,10 @@ def is_image(toot):
for media in toot.media_attachments:
if media["type"] == "gifv" or media["type"] == "image":
return True
def get_media_urls(toot):
urls = []
for media in toot.media_attachments:
if media.get("type") == "audio" or media.get("type") == "video":
urls.append(media.get("url"))
return urls