python - 我想在一天中的某个时间在 python 中播放声音剪辑,但是当我使用“或”添加另一个时间段时,它会继续播放
问题描述
import time
from datetime import datetime
while(True):
t = datetime.now()
tn = t.strftime("%H:%M:%S")
time.sleep(1)
print(tn)
print(type(tn))
if tn == "15:20:00":
from pygame import mixer
mixer.init() # Starting the mixer
mixer.music.load('water.wav') # Loading the song
mixer.music.set_volume(0.7) # Setting the volume
mixer.music.play(loops=-1) # Start playing the song in loop
inp = input("enter the defuse code")
if inp == "drank":
mixer.music.stop()
else:
pass
该程序将在 13:20:00 完美播放音乐,但如果我也想在 13:40:00 播放此声音并将 ' if tn == "15:20:00": ' 更改为 'if tn == “15:20:00”或“15:40:00”
即使时间介于这两者之间,它也不会停止播放音乐
解决方案
推荐阅读
- sql - 多列sql上的多关键字搜索
- cuda - 单线程中的矢量化原子添加
- python - 使用 csv.writer 直接写入二进制模式
- corda - 无法在corda中进行流量测试
- python - 为什么我无法在 Paho MQTT 中接收消息?
- android - 是否可以因为 Asyncstorage 库中的警告而删除 buildToolsVersion android studio?
- java - 如何转换 @RequestParam 映射
到自定义地图<> - node.js - firebase aync 等待在 try catch 中获取空对象
- django - ForeignKey 模型的下载链接
- java - 在以下情况下检查重复答案的有效方法是什么?