【问题标题】:is there any way to play sound using qpython?有没有办法使用 qpython 播放声音?
【发布时间】:2016-01-11 22:21:00
【问题描述】:

我正在尝试在 qpython 中运行以下脚本。您能否建议 mpg321 在 android 中的替代方案?

import os
from time import sleep as sleep

pwd = os.path.dirname(os.path.abspath(__file__))
os.chdir(pwd)

work_time = int(raw_input("give the working time. Default time is 25 minutes : ") or "25")
chill_time = int(raw_input("give the chill out time. Default time is 3 minutes : ") or "3")
total_time = int(raw_input("give the total working time. Default is 3 hours : ") or "3")*60

loop_count = (total_time/(work_time+chill_time+1))+1



def notificationsystem(work_time, chill_time):
    print "stop procrastinating and start working"
    os.system('mpg321 start.mp3 &')
    sleep(work_time*60)
    print ("take a break for %s minutes" % chill_time)
    os.system('mpg321 stop.mp3 &')
    sleep(chill_time*60)


while loop_count > 0:
    notificationsystem(work_time, chill_time)
    loop_count -= 1

【问题讨论】:

    标签: python qpython


    【解决方案1】:

    你可以试试内置的 sl4a 模块:

    import sl4a
    ad = sl4a.Android()
    ad.mediaPlay("/your/path/to/sound.mp3")
    

    【讨论】:

    • 当我尝试导入 sl4a 时,它说找不到模块。我还尝试使用 pip.main(['install','sl4a']) 安装 sl4a,但它没有用。不过,我可以下载一些其他模块,例如请求。知道 sl4a 发生了什么吗?
    • 你可以尝试导入android,而不是sl4a,它做同样的事情。另外,您是否尝试过重新安装 QPython?
    • 是的,我尝试重新安装 QPython,然后尝试安装 sl4a。它没有用。但是,“从 androidhelper 导入 Android”有效!谢谢。作为替代,您也可以建议/将其添加为答案中的替代!!
    【解决方案2】:

    如果您使用的是 android 设备,则可以导入 androidhelper 并使用 mediaPlay("start.mp3")...

    或者最好使用 kivy 将您的控制台应用程序转换为 gui 应用程序 并使用kivy.core.audio.SoundLoader("start.mp3")...

    kivy 值得学习...它适用于台式机和机器人

    【讨论】:

      【解决方案3】:

      ad.mediaPlay works!

      现在开始播放后如何停止播放?

      我找到了!

      ad.mediaPlayClose()

      并且他们的播放时间可以通过

      来控制

      ad.eventWait(4000)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多