Page 1 of 1

MP3 -Dateien in Beeware abspielen

Posted: 05 Mar 2025, 13:32
by Anonymous
Ich experimentiere mit Python / Beeware / Toga / Android. Ich möchte eine MP3-Datei öffnen.

Code: Select all

async def pate_tlacitko(self, widget):
from toga.platform import current_platform
if current_platform == "android":
from android.content import Intent
from android.net import Uri
from java.io import File

intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_APP_MUSIC)

await self.app._impl.intent_result(intent)
< /code>
Nach dem Aufrufen der Funktion erhalte ich die Auswahl der Anwendung, um den Sound abzuspielen.    async def pate_tlacitko(self, widget):
from toga.platform import current_platform
if current_platform == "android":
from android.content import Intent
from android.net import Uri
from java.io import File

intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_APP_MUSIC)
intent.setDataAndType(Uri.fromFile(File(str("resources/test.mp3"))), "application/mp3")
await self.app._impl.intent_result(intent)

←[33mW/python.stderr: android.os.FileUriExposedException: file:///resources/test.mp3 exposed beyond app through Intent.getData()←[0m
< /code>
Wie definiere ich eine Datei zum Spielen? Idealerweise wäre es, eine Datei aus dem Musikverzeichnis abzuspielen.android_manifest_extra_content = [
"",
"",
""
]