question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Playing an Audio widget programmatically?

See original GitHub issue

I tried to play an Audio widget programmatically, but I don’t see a play()-like method to do that, like:

from ipywidgets import Audio
w = Audio.from_file("audio/a.mp3", autoplay=False, loop=False)
w.play()
# AttributeError: 'Audio' object has no attribute 'play'

Is it possible?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jasongroutcommented, Feb 9, 2021

tl;dr: I support adding a playing attribute to the audio/video widgets, and would support adding a volume attribute as well.

Currently the audio and video widgets have the following attributes exposed from the HTML media element:

  • autoplay - start playing immediately on display
  • loop - loop the audio
  • controls - boolean saying whether the browser should display controls.

I think it makes sense to expose others that help in managing the media element. From https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement, for example, we could expose:

  • volume (there is an event for volumechange we can use to notify the python side)
  • and also, as suggested here, a playing attribute that uses the .play() and .pause() methods to control the playback, and there are play/pause events we can use to notify the python side

There are some other attributes we could expose like muted and playbackRate, but it’s not clear (a) how useful it would be and (b) what events could be used to send notification back to python if they changed from user interaction.

1reaction
nmstokercommented, Sep 14, 2021

My autoplay method is clunky and won’t give the kind of control that lets you stop playback, but it would work to trigger playback programmatically if you didn’t mind the side effects.

Generally speaking though a better solution (eg with widget code /use of web audio API as you mention) seems the smarter way to go, but I don’t know if there’s any progress there

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make an audio player widget in android - Stack Overflow
I want to make an audio player widget in which I have added there buttons for play , next and previous.Widget should show...
Read more >
How to Play Audio from URL in Android? - GeeksforGeeks
How to Play Audio from URL in Android? · Step 1: Create a New Project · Step 2: Working with the activity_main.xml file...
Read more >
MediaPlayer overview - Android Developers
This class is the primary API for playing sound and video. AudioManager: This class manages audio sources and audio output on a device....
Read more >
Playing Audio in android Example - Javatpoint
package com.example.audiomediaplayer1; · import android.media.MediaPlayer; · import android.net.Uri; · import android.os.Bundle; · import android.app.Activity; ...
Read more >
Build Full Music Player App in iOS & Swift Programmatically
Visit us at https://www.devtechie.com Downloadable content and source code(for new videos): https://www.patreon.com/DevTechieInc Spotify ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found