[Python] Playing MP3 files in Beeware

Discussão em 'Python' iniciado por Stack, Março 3, 2025.

  1. Stack

    Stack Membro Participativo

    Playing MP3 files in Beeware

    Hi, I'm experimenting with Python / Beeware / Toga / Android. I would like to open an MP3 file.

    The first part works:

    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)


    After calling the function, I get a choice of application to play the sound.

    If I add a line that defines the set to play, I get an error:

    intent.setDataAndType(Uri.fromFile(File(str("resources/test.mp3"))), "application/mp3")

    ←[33mW/python.stderr: android.os.FileUriExposedException: file:///resources/test.mp3 exposed beyond app through Intent.getData()←[0m


    How do I define a file to play? Ideally, it would be to play a file from the Music directory.

    THX

    Continue reading...

Compartilhe esta Página