How to show a video on a Jupyter widget on a Jupyter Notebook

gota

Assume I have a folder with 4 video files (named like "movie1.mp4", "movie2.mp4" etc.)

I want to use ipywidgets to let the user control which video he desires to see. Like this:

import ipywidgets as wd
from IPython.display import HTML

def showvideo(i):
    HTML("""<video width="100" height="100" controls><source src="movie{}.mp4" type="video/mp4"></video>""".format(i))

wd.interact(showvideo, video_number = [1, 2, 3, 4]);

This doesn't work. but simply calling

from IPython.display import HTML

HTML("""<video width="100" height="100" controls><source src="movie1.mp4" type="video/mp4"></video>""")

works

Is there some python magic that I need to call?

Louise Davies

You aren't actually displaying the result. Jupyter automatically attempts to display the result of the last line of code in a cell, so that's why your HTML is displaying when doing it manually, but if you are calling it progrmamatically or your HTML isn't on the last line, you have to manually call display() on your HTML.

Additionally, you aren't specifying the parameter correctly. The parameter name in the function has to match what you supply to interact. Changing your code to this should work:

def showvideo(video_number):
    display(HTML("""<video width="100" height="100" controls><source src="movie{}.mp4" type="video/mp4"></video>""".format(video_number)))

wd.interact(showvideo, video_number = [1, 2, 3, 4]);

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to have multiple widget buttons perform different actions in Jupyter Notebook?

分類Dev

IPython/Jupyter notebook widget span full width

分類Dev

How to run jupyter notebook in airflow

分類Dev

How to rename a Jupyter Notebook programmatically?

分類Dev

How to show both the random data and the descriptive stats of the dataset in one cell? (Jupyter notebook, pandas)

分類Dev

how to convert audio data to fourier on jupyter notebook?

分類Dev

How to obtain Jupyter Notebook's path?

分類Dev

How to stop the Jupyter Server inside a Pycharm notebook

分類Dev

How to lazify output in Tabbed Layout in jupyter notebook?

分類Dev

Jupyter notebook and Anaconda Navigator does not show after installing Anaconda

分類Dev

show all rows and cols from print jupyter notebook

分類Dev

Way to show multiple spaces in Pandas Dataframe on Jupyter Notebook

分類Dev

Copy to clipboard in jupyter notebook

分類Dev

Output widget appears outside tab widget when using nbconvert on jupyter notebook with ipywidgets

分類Dev

How do I document the Jupyter Notebook Profile startup?

分類Dev

How to execute a bash script from a Python string in Jupyter Notebook?

分類Dev

How do you suppress matplotlib output in for loop in Jupyter Notebook?

分類Dev

How to use sink() to save R output in Jupyter notebook?

分類Dev

Jupyter notebook, how to execute system shell commands in the right conda environnment?

分類Dev

How can I disable the autocomplete function in Jupyter notebook(Tab)

分類Dev

How load docker-machine env inside Jupyter Notebook?

分類Dev

VSCode: How to run a Jupyter notebook in a docker container, over a remote server?

分類Dev

How to display a text paragraph next to figure in jupyter/ipython notebook

分類Dev

Jupyter Notebook Extensions Fail to Load

分類Dev

matplotlib: figimage not showing in Jupyter notebook

分類Dev

displaying grid of images in jupyter notebook

分類Dev

Using jupyter notebook shortcuts in colaboratory

分類Dev

No module named graphframes Jupyter Notebook

分類Dev

Jupyter NotebookのMatplotlib .show()のDPIを増やす

Related 関連記事

  1. 1

    How to have multiple widget buttons perform different actions in Jupyter Notebook?

  2. 2

    IPython/Jupyter notebook widget span full width

  3. 3

    How to run jupyter notebook in airflow

  4. 4

    How to rename a Jupyter Notebook programmatically?

  5. 5

    How to show both the random data and the descriptive stats of the dataset in one cell? (Jupyter notebook, pandas)

  6. 6

    how to convert audio data to fourier on jupyter notebook?

  7. 7

    How to obtain Jupyter Notebook's path?

  8. 8

    How to stop the Jupyter Server inside a Pycharm notebook

  9. 9

    How to lazify output in Tabbed Layout in jupyter notebook?

  10. 10

    Jupyter notebook and Anaconda Navigator does not show after installing Anaconda

  11. 11

    show all rows and cols from print jupyter notebook

  12. 12

    Way to show multiple spaces in Pandas Dataframe on Jupyter Notebook

  13. 13

    Copy to clipboard in jupyter notebook

  14. 14

    Output widget appears outside tab widget when using nbconvert on jupyter notebook with ipywidgets

  15. 15

    How do I document the Jupyter Notebook Profile startup?

  16. 16

    How to execute a bash script from a Python string in Jupyter Notebook?

  17. 17

    How do you suppress matplotlib output in for loop in Jupyter Notebook?

  18. 18

    How to use sink() to save R output in Jupyter notebook?

  19. 19

    Jupyter notebook, how to execute system shell commands in the right conda environnment?

  20. 20

    How can I disable the autocomplete function in Jupyter notebook(Tab)

  21. 21

    How load docker-machine env inside Jupyter Notebook?

  22. 22

    VSCode: How to run a Jupyter notebook in a docker container, over a remote server?

  23. 23

    How to display a text paragraph next to figure in jupyter/ipython notebook

  24. 24

    Jupyter Notebook Extensions Fail to Load

  25. 25

    matplotlib: figimage not showing in Jupyter notebook

  26. 26

    displaying grid of images in jupyter notebook

  27. 27

    Using jupyter notebook shortcuts in colaboratory

  28. 28

    No module named graphframes Jupyter Notebook

  29. 29

    Jupyter NotebookのMatplotlib .show()のDPIを増やす

ホットタグ

アーカイブ