简体   繁体   English

在复制中播放 python 中的音乐

[英]Playing music in python in replit

I'm having trouble playing music in the background of my program in replit.我无法在 repli 中的程序背景中播放音乐。 I have tried using Pygame but couldn't get that to work, so I followed the official replit tutorial video: https://youtu.be/CuIV2-ivg0U .我曾尝试使用 Pygame 但无法使其正常工作,因此我按照官方复制教程视频进行操作: https://youtu.be/CuIV2-ivg0U I get the confirm audio screen but nothing plays, my file is.wav and is 29 secs long and plays when I go directly onto the file, but not when the program runs.我得到确认音频屏幕,但没有播放,我的文件是.wav,长 29 秒,当我将 go 直接播放到文件时播放,但在程序运行时不播放。 I have uploaded the file into replit so it appears alongside main.py, any help would be appreciated, let me know if any additional info is needed, Thanks.我已将文件上传到 replit,因此它与 main.py 一起出现,任何帮助将不胜感激,如果需要任何其他信息,请告诉我,谢谢。

My code:我的代码:

from replit import audio
source = audio.play_file("music.wav")
while True:
  pass

For some odd reason, replit doesn't actually let you run code alongside the playing of music.出于某种奇怪的原因,replit 实际上并不允许您在播放音乐的同时运行代码。 Get rid of摆脱

while True:
    pass

It should work then它应该工作

look at this -- https://docs.replit.com/tutorials/audio看看这个——https://docs.replit.com/tutorials/audio
replit has trouble using repli 使用有问题

    while True:
       pass

if you want to do nothing while the audio file is running, instead use time.sleep如果您不想在音频文件运行时执行任何操作,请改用 time.sleep
you should also be able to run code while the file is running with no problems您还应该能够在文件运行时运行代码而没有问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM