HTML5音频元素在IPythonNB容器小部件中消失

时间:2022-10-04 07:11:50

This code:

from IPython.display import display
from IPython.html import widgets
snd = """
<audio controls="controls" style="width:600px height:100px">
<source controls src="data:audio/wav;base64,UklGRiYAAABXQVZFZm10IBAAAAABAAEAYCIAAAATAQAIAEAAZGF0YQgAAAAAAA==" type="audio/wav" />
Your browser does not support the audio element.
</audio>"""
snd_widget = widgets.HTML(snd)
container = widgets.Box(children=[snd_widget])
display(container)

...produces my audio player within the container widget like I expect, but then promptly vanishes. It actually has a nice fade-away effect. However, I do not wish it to disappear; I want to be able to interact with it. It is briefly visible again if I close the interactive element, so I have to believe there is some simple display bug I hope to work around.

...像我期望的那样在容器小部件中生成我的音频播放器,但随后立即消失。它实际上有一个很好的淡出效果。但是,我不希望它消失;我希望能够与它互动。如果我关闭交互元素,它会再次短暂可见,所以我不得不相信有一些简单的显示错误我希望能够解决。

snd_widget.disabled is False and snd_widget.visible is True

snd_widget.disabled为False,snd_widget.visible为True

display(snd_widget) (without using ContainerWidget/Box) has the same effect.

display(snd_widget)(不使用ContainerWidget / Box)具有相同的效果。

Problem seems browser-specific: Problem exists on Firefox, but display seems fine on Chromium.

问题似乎特定于浏览器:Firefox上存在问题,但在Chromium上显示似乎很好。

1 个解决方案

#1


This seems to be Firefox's behavior for malformed audio files. Unfortunately both my work sample and this simple test sample were both malformed. Firefox will hide the player if it can't play the file, Chromium will grey out the player after a short time.

这似乎是Firefox对格式错误的音频文件的行为。不幸的是,我的工作样本和这个简单的测试样本都是畸形的。如果播放器无法播放文件,Firefox将隐藏播放器,Chromium会在短时间内使播放器变灰。

#1


This seems to be Firefox's behavior for malformed audio files. Unfortunately both my work sample and this simple test sample were both malformed. Firefox will hide the player if it can't play the file, Chromium will grey out the player after a short time.

这似乎是Firefox对格式错误的音频文件的行为。不幸的是,我的工作样本和这个简单的测试样本都是畸形的。如果播放器无法播放文件,Firefox将隐藏播放器,Chromium会在短时间内使播放器变灰。