Google Colab. IPython.display - Audio not working in if statement

Viewed 2101

Just started learning Python. I met a strange behaviour of Audio in if statement. It should work, but is not working.

See example here: https://colab.research.google.com/drive/1Jz6znaj047zrtDK-orp8VN0869xDYnQO?usp=sharing

This code works fine (plays wav file):

from IPython.display import Audio

sound_hey = "http://thecyberbuddy.com/sounds/hooray.wav"

Audio(sound_hey, autoplay=True)  # plays ok

And this not:

from IPython.display import Audio

sound_boo = "http://mrclan.com/fastdl/tfc/sound/boo.wav"

s = 1

if s == 1:
  Audio(sound_boo, autoplay=True)  # dose not play...
1 Answers

Here

from IPython.display import Audio, display

sound_boo = "http://mrclan.com/fastdl/tfc/sound/boo.wav"

s = 1

if s == 1:
  display(Audio(sound_boo, autoplay=True))
Related