Code Monkey home page Code Monkey logo

react-h5-audio-player's Introduction

logo

React H5 Audio Player

  • Audio player component that provides consistent UI/UX on different browsers.
  • Super customizable layout
  • Flexbox css with SVG icons. Mobile friendly.
  • I18n and a11y supported, keyboards events supported.
  • Support Media Source Extensions (MSE) and Encrypted Media Extensions (EME)
  • Written in TypeScript.

screenshot

Live Demo: Storybook

Try it on CodePen: Basic, Playlist

Supported browsers: Chrome, Firefox, Safari, Edge

Installation

$ npm i react-h5-audio-player

Or

$ yarn add react-h5-audio-player

Usage

import AudioPlayer from 'react-h5-audio-player';
import 'react-h5-audio-player/lib/styles.css';
// import 'react-h5-audio-player/lib/styles.less' Use LESS
// import 'react-h5-audio-player/src/styles.scss' Use SASS

const Player = () => (
  <AudioPlayer
    autoPlay
    src="http://example.com/audio.mp3"
    onPlay={e => console.log("onPlay")}
    // other props here
  />
);

Keyboard shortcuts (When audio player focused)

They can be turned off by setting hasDefaultKeyBindings prop to false

Key binding Action
Space Play/Pause
Rewind
Forward
Volume up
Volume down
L Toggle loop
M Toggle mute

Props

HTML Audio Tag Native Attributes

Props Type Default Note
src string ''
preload 'auto' | 'metadata' | 'none' 'auto'
autoPlay boolean false Won't work on most mobile devices
loop boolean false
muted boolean false
volume number 1.0 Won't work on most mobile devices
crossOrigin string undefined
mediaGroup string undefined

More native attributes detail: MDN Audio element

The controls attribute defaults to false and should never be changed to true because this library is already providing UI.

UI/UX Props

Props Type Default Note
showSkipControls boolean false Show Previous/Next buttons
showJumpControls boolean true Show Rewind/Forward buttons
showDownloadProgress boolean true Show download progress over progress bar
showFilledProgress boolean true Show filled (already played) area on progress bar
showFilledVolume boolean false Show filled volume area on volume bar
hasDefaultKeyBindings boolean true Whether has default keyboard shortcuts
autoPlayAfterSrcChange boolean true Play audio after src is changed, no matter autoPlay is true or false
volumeJumpStep number 0.1 Indicates the volume jump step when pressing up/down arrow key, volume range is 0 to 1
progressJumpStep number 5000 Deprecated, use progressJumpSteps. Indicates the progress jump step (ms) when clicking rewind/forward button or left/right arrow key
progressJumpSteps object { backward: 5000, forward: 5000 } Indicates the progress jump step (ms) when clicking rewind/forward button or left/right arrow key
progressUpdateInterval number 20 Indicates the interval (ms) that the progress bar UI updates,
listenInterval number 1000 Indicates the interval (ms) to call the onListened prop during playback
defaultCurrentTime ReactNode '--:--' Default display for audio's current time before src's meta data is loaded
defaultDuration ReactNode '--:--' Default display for audio's duration before src's meta data is loaded
timeFormat 'auto' | 'mm:ss'
| 'hh:mm:ss'
'auto' Time format for both current time and duration. 'auto' means when duration is greater than one hour, time format is hh:mm:ss, otherwise it's mm:ss
header ReactNode null Header of the audio player
footer ReactNode null Footer of the audio player
layout 'stacked' | 'horizontal' |
'stacked-reverse' |
'horizontal-reverse'
'stacked' Overall layout of the audio player
customIcons CustomIcons {} Custom icons to replace the default ones
customProgressBarSection Array<string |
ReactElement>
[CURRENT_TIME,
PROGRESS_BAR,
DURATION]
Custom layout of progress bar section
customControlsSection Array<string |
ReactElement>
[ADDITIONAL_CONTROLS,
MAIN_CONTROLS,
VOLUME_CONTROLS]
Custom layout of controls section
customAdditionalControls Array<string |
ReactElement>
[LOOP] Custom layout of additional controls
customVolumeControls Array<string |
ReactElement>
[VOLUME] Custom layout of volume controls
i18nAriaLabels I18nAriaLabels I18nAriaLabels A configuration object to overwrite the default aria-label on the action buttons
mse Object null A configuration object so the player can play audio chunks, MSE streams and encrypted audio (See section about Media Source Extensions in this Readme)
mse.srcDuration number - The complete duration of the MSE audio chunks together (this is a key of the mse prop)
mse.onSeek Function (Event) - The callback to be used when seek happens (this is a key of the mse prop)
mse.srcDuration number - The callback to be used when encrypted audio is detected and needs to be decrypted (this is a key of the mse prop)

Event Props

Supported media events: onPlay, onPause, onEnded, onSeeking, onSeeked, onAbort, onCanPlay, onCanPlayThrough, onEmptied, onError, onLoadStart, onLoadedMetaData, onLoadedData, onPlaying, onSuspend, onWaiting, onVolumeChange

Docs: Media Events | MDN

Note: onTimeUpdate is not supported. Please use onListen with listenInterval for better performance.

Other events

Props Type Default Note
onClickPrevious Function (Event) null Called when click Previous button
onClickNext Function (Event) null Called when click Next button
onListen Function (Event) null Called every listenInterval milliseconds during playback
onPlayError Function (Error) null Called when there's error invoking audio.play(), it captures error that onError won't catch
onChangeCurrentTimeError Function () null Called when dragging progress bar or press rewind/forward while the audio hasn't loaded yet

UI Overwrites

Besides using props to change UI, React H5 Audio Player provides built-in class names and SASS/LESS variables for developers to overwrite.

SASS variables

$rhap_theme-color: #868686 !default;   // Color of all buttons and volume/progress indicators
$rhap_background-color: #fff !default; // Color of the player background
$rhap_bar-color: #e4e4e4 !default;     // Color of volume and progress bar
$rhap_time-color: #333 !default;       // Font color of current time and duration
$rhap_font-family: inherit !default;   // Font family of current time and duration

For LESS variables, just replace $ with @. This library supports both.

Status class names

There are some status class names on the audio player's wrapper div. They can be used for overwriting styles.

className Description
rhap_loop--on Loop is on
rhap_loop--off Loop is off
rhap_play-status--paused Paused status
rhap_play-status--playing Playing status

For example:

.rhap_play-status--paused .rhap_progress-bar {
  // Overwrite the progress bar style while the audio is paused
}

Advanced Usage

Access to the audio element

You can get direct access to the underlying audio element. First get a ref to ReactAudioPlayer:

this.player = createRef()

<ReactAudioPlayer ref={this.player} />

Then you can access the audio element like this:

this.player.current.audio.current

Media Source Extensions and Encrypted Media Extensions

You can use Media Source Extensions and Encrypted Media Extensions with this player. You need to provide the complete duration, and also a onSeek and onEncrypted callbacks. The logic for feeding the audio buffer and providing the decryption keys (if using encryption) must be set in the consumer side. The player does not provide that logic. Check the StoryBook example to understand better how to use.

Release Notes

https://github.com/lhz516/react-h5-audio-player/releases

How to contribute

Issues and PR's are welcome.

Credits

react-h5-audio-player's People

Contributors

altef avatar bakerhimself avatar bleuarg avatar clarehuang avatar dependabot[bot] avatar diegochappedelaine avatar ferdiamg avatar l0gicgate avatar lhz516 avatar ptmkenny avatar sergiocrisostomo avatar shannon-hibbett-m3 avatar snelsi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-h5-audio-player's Issues

Fast Forward and Backward audio on button click

Hello @lhz516 ,

I really like this player - nice and customizable.

I would like to request a new feature to fast forward and backward an audio, so that when forward/backward buttons are clicked it can be forwarded and backward up-to particular time interval.

When used with form libraries, control buttons trigger form submission because of lack of type

Describe the bug
Forms that have this audio player rendered, will trigger form submission when one of the main control buttons are clicked.

Screen Shot 2020-04-14 at 3 02 04 PM

Warning: You submitted a Formik form using a button with an unspecified `type` attribute.  Most browsers default button elements to `type="submit"`. If this is not a submit button, please add `type="button"`.

Can we have the type specified as "button" to prevent this from happening? e.stopPropagation() will not prevent this behavior from happening.

Suggested Fix:

<button
  aria-label={isPlaying ? 'Pause' : 'Play'}
  type="button" //  <-- Fix
  className="rhap_button-clear rhap_main-controls-button rhap_play-pause-button"
  onClick={this.togglePlay}
>
  {actionIcon}
</button>

Environment

Package version: "react-h5-audio-player": "^3.0.4",
React version: "react": "^16.8.2",
Browser and its version: Chromium
OS and its version: macOS Mojave 10.14.6 (18G95)

Progress bar and volume bar knobs stick to cursor after right click

Sorry to bombard you with all these issues I'm creating 😄, I really appreciate your work though!

Steps to reproduce:

  1. Right click anywhere on the progress bar or volume bar
  2. Dismiss the context menu (left-click somewhere on the page)
  3. Move mouse cursor around

Observed:
The knob continues to follow the cursor until an additional left-click is registered.

Expected:
The knob should not follow the cursor.

This also happens if you Right click > Inspect Element instead of dismissing the menu.

Browser and its version: Chrome 83.0.4103.23
OS and its version: macOS 10.15.5 Beta (19F62f)

Attribute "volume" is not allowed on element "audio"

from the W3 validator:

Error: Attribute volume not allowed on element audio at this point.

From line 945, column 2098; to line 945, column 2218

<audio src="my.mp3" title="my.mp3" volume="1" preload="auto">

Attributes for element audio:
Global attributes
src — Address of the resource
crossorigin — How the element handles crossorigin requests
preload — Hints how much buffering the media resource will likely need
autoplay — Hint that the media resource can be started automatically when the page is loaded
loop — Whether to loop the media resource
muted — Whether to mute the media resource by default
controls — Show user agent controls

Support Media Source Extensions and EME

This is a feature request question.

W3C defined specs for Media Source Extensions and Encrypted Media Extensions. This specification allows JavaScript to dynamically construct streams for <audio>. It defines a MediaSource object that can serve as a source of media data for an HTMLMediaElement, instead of just passing a URL.

There are more advanced players like DASH, HLS, Shaka, etc. These are very complex video players that can play audio if the audio format is following their standard (dash .mpd manifest, or HLS .m3u8 manifest). But there is a use case for more simple and generic uses where the app using has its own logic for audio streams.

I think it would be good to be able to support the W3C standard in its most simple form, ie:

  • enabling the use of MSE
  • enabling Clear Key encryption events and callbacks

In practical terms this means:

  • adding a callback for EME events encrypted, message, keystatuseschange
  • adding mechanism to set the length display so we can show the track length
  • enable seek functionality
  • (maybe, not tested) correct the loaded progress bar to show properly the chunks that are loaded

I suggest minimal additions in the H5 player, as far as possible putting the MSE/EME logic on the consumer of the player. These changes would expand the use case of this player to consuming audio streams.

I am happy to implement this if you think might be useful. Happy to hear your thoughts.

Audio not autoplaying upon first src change

I'm using useContext to update the media player from multiple pages within my app.
This works as it should, however when the app starts up for the first time, the src is set to an empty string. Once play is clicked, the information is updated on the media player (ie the image, name and audio time is visible) but the media is paused.
If I change to a different audio src after this, the media plays (as it should on src change).

Just wanting to find out if there is a way to have the media play on src change, when the previous src is either an empty string or undefined?

V3 Roadmap

The audio player V3 will mainly solve some historical issues and introduce a flexible layout feature.

  • Drop support under React 16.3.0 so that createRef API and some new lifecycles can be used
  • Drop support of IE10 since it had stopped being maintained by Microsoft after 1/14/2020
  • onListen's argument will be changed from current time number to Event object
    • You can still get current time by event.target.currentTime
  • Ultra flexible layout (Props name TBD)
    • custom action buttons which are sortable with built-in buttons

The default view of V3 will be exactly the same as V2. If you are already using React 16.3.0+, you almost don't need to migrate anything unless you used onListen props.

Feel free to give any suggestions.

Type definitions for package

It would be great to have type definitions in this, so that this can be used nicely within Typescript, instead of having to hack it around to import a javascript component.

Feature Request: Use custom svgs for buttons

What do you think about the idea of making it possible to use custom images as buttons?
I was for example thinking about using a 10-sec-fast-forward button (used by Netflix on iOS for example).
image

Any tips on how to implement that? Thank you so much again for this great product!

Autoplay happens even when flag is false

I have a List component which displays a list of options, let's say movie names. Once a movie is selected, details component should display audio player. The problem is that when I switch movies in the List, player starts autoplay although I specify autoplay as false or simply omit it. How can I prevent autoplay?
In addition, console displays errors:
index.js:1 Uncaught Error: The error you provided does not contain a stack trace.
at S (index.js:1)
at V (index.js:1)
at index.js:1
at index.js:1
at a (index.js:1)
S @ index.js:1
V @ index.js:1
(anonymous) @ index.js:1
(anonymous) @ index.js:1
a @ index.js:1
react-dom.development.js:1350 Uncaught (in promise) DOMException: The play() request was interrupted by a new load request. https://goo.gl/LdLk22

Custom step value for forward/backward jump.

Hi, first of all thanks for you work on that component!

I have a use case where I want the skip forward and skip backward button to jump a different amount of time (as in some podcast players).

ex: forward 30 sec and backward 10 sec.

I was thinking something like that. I would be happy to submit a PR if that is something you are willing to add.

showing infinity

Screenshot from 2019-12-12 12-46-30
it is displaying infinity and Nan
why it is happening ?
once we played it, next time onwards works fine.. only first time plays this happens

Way to play and pause

Way to play and pause

I need to implement my own play and pause. In my app, I'm using a mini player and I'm hiding the main audio-player. At the mini-player, you can see the title and play, pause button.
If clicked on the mini player it shows the main audio player(react-h5-audio-player)

I'm using this to get the ref

this.player = createRef()
<ReactAudioPlayer ref={this.player} />

At the UI if pause button is clicked I'm using
PlayerRef.current.audio.current.pause(); to pause the audio and it works
If clicked on the play button, I'm using
PlayerRef.current.audio.current.play(); but at this time the player ref is null. Is there any way to persist the ref? or is there any other way to do it?

Thanks in advance!

Is there a way to async load the playlist from an API?

Hi,
I've been trying to load an api to put into the playlist such as your example. Perhaps I am a bit junior on react but I just tried to have a getaudiourl as a function on the object but because the api is a fetch I can't access the this object and I can't figure out the async syntax for functions in the current structure. My apologies if this seems like a junion problem.

event volume changed

Hi, I want to know if there is an event to manage the volume changed event.
in this way I can save the level and if I reload the page I don't have the max level volume.
Thank you very much
Angelo

Support responsive layout for width < 300px

I want to request supporting alternative layouts where the audio player cannot fit. Right now the width of the player is capped to 300px, even if its parent element may be smaller. This can cause it to look weird especially on smaller screens.

A related request, can you look into supporting a bare minimal layout, where the audio player is simply a Play/Stop button? No seek bar, no timestamps, no pause, no volume, etc. Press to play, press again to stop the player and reset position to beginning of track.

Screen Shot 2020-04-23 at 5 35 38 PM

Then, as you resize the page it should transition from the minimal layout to the regular layout.

When src changes and autoPlayAfterSrcChange is true , icon changes to pause.

How to reproduce it
-Audio is pause or playing
-Click on skipControls
Audio starts or continues, but the icon changes to pause icon

Expected
Icon changes or continues to play icon

Environment

Package version: 3.0.0-rc.2
React version: 16.12.0
Browser and its version: Google Chrome 80.0.3987.132
OS and its version: Windows 10

[Feature Request] Would like to have current time in reverse.

First of all, thank you for the amazing library, I would like to ask for a UI feature to be able to show current time as (total time - current played time). For example, the audio is 2 min long, and then it is already played for 30 seconds, it should show "1:30"

Icon cut off at bottom

For some reason my play button is getting cut off at the bottom. The relevant portion of my code:

<div style={{backgroundColor: "red", height: "200px"}}> <AudioPlayer autoPlay src="http://example.com/file.mp3" onPlay={e => console.log("onPlay")} // other props here /> </div>
Any ideas why this might be? At first I thought it was my parent container. However, I have now enlarged that as shown in the attached picture but still have the same problem.

audio_h5

File not playing in iOS

Describe the bug

A clear and concise description of what the bug is, and how to reproduce. Screenshots are appreciated.

In short:
In my application the mediaplayer receives a filestream from the server, which can then be played. Instead of a direct link to the mp3, the mediaplayer receives a signed URL, that returns a binary audio/mpeg stream when requested. This is mainly to prevent file sharing outside the website and hotlinking. On iOS however, This works in 90% of the audio files, but in some cases the audio player doesn't seem to read the stream.

For example this radioshow recording:
https://www.radiomerlijn.nl/uitzending-gemist/transformatie-academie
Playback works fine when played in a desktop browser i.e. Chrome. But on iOS, the current time and duration remain blank.
IMG_5039

On many of the other pages, the audio files are loaded and can be played in iOS and desktop browsers without any issues. For example on:
https://www.radiomerlijn.nl/uitzending-gemist/meditatie

The audio files are produced by the same audio software. I tried uploading the audio files with different filenames, and in the backend I tried different response headers (Content-Disposition: attachment; filename="audiofile.mp3"). But so far the results remain exactly the same.

Current content headers:

  $headers = array (
            'Accept-Ranges: 0-' . (filesize($path) - 1),
            'Content-Length:' . filesize($path),
            'Content-Type: audio/mpeg',
            'Content-Disposition: inline',
        );

Environment

Package version: 3.1.0
React version: 16.13.1
Browser and its version: Chrome and Safari for iOS
OS and its version: iOS 13.4.1

Radio stream without caching

Hello, is it possible to play a radio stream without caching? When you press the pause, the downloaded data is cached in the player, and after you press the start button, they are played from the moment of pause, and not what is played in the radio stream.

Next Button not firing

Describe the bug

When I click the next button with the following code, no console long is sent. Additionally it only fast forwards 5 seconds.

    autoPlay
    loop
    footer
    ref={player}
    src="http://aivibes.s3.amazonaws.com/hip_hop/HipHop%20(10).mp3"
    onPlay={e => console.log("onPlay")}
    onClickNext={e => console.log("onNextClick")}
    onListen={e => console.log("onListenInterval")}
    onEnded={e => console.log("onEnd")}
    // other props here
  /> ````


My use case is I wanted to load an array of songs into the player for the next song, but arrays didn't seem to work, so I thought I can use the next and end of song events to load the next song. But neither or those events ever fire to run my functions. 

Playing multiple src at the same time

Hey great package, I was wondering if you guys were thinking of implementing an array of src audio files to be played together, or even if this is currently possible?

Thanks for your time

Extra spacing in horizontal layout

Describe the bug

I am using the component like this:

<AudioPlayer
          src=""
          showJumpControls={false}
          customVolumeControls={[]}
          customAdditionalControls={[]}
          layout="horizontal"
        />

To me there's too much spacing around the play button.
Screen Shot 2020-04-23 at 4 14 33 PM

Package version: 3.0.5
React version: 16.13.1
Browser and its version: Chrome 83
OS and its version: macOS 10.15.5

Scrub bar is broken when the page is horizontally scrolled

Describe the bug

The X offset of the touch position when clicking on the scrub bar is wrong when the page is scrolled horizontally by any amount. It's easily reproducible in the demo CodePen linked in the README. Just make the component wider and the browser window small, then scroll horizontally and try to scrub.

Environment

Package version: 3.3.0
React version: 16.13.1
Browser and its version: latest Chrome and Safari
OS and its version: macOS 10.15.6

multi-audio played at the same time

Describe the bug

it doesn't listen to the play function correctly, it causes multi-audio played at the same time.

Screen Shot 2020-03-06 at 11 01 32 AM

Environment

Package version: 2.4.2
React version: ^16.12.0
Browser and its version:

OS and its version:

Player does not unmount on component change

Hello,

It is maybe something I am doing wrong but I have to ask, I have tried a lot to fix this with no luck.

I have a list of tracks on browse component, when I click on one, player component with react-h5 player in it, It fetched the audio source with GraphQl and provide to react-h5, everthing working as expected but when I click on menu back to track lists, playing stops and I get this warning in console "index.js:1 Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method." . But if I use the Play/Pause button on keyboard the track plays again in background.
No warning when I pause the player and go back to track lists. But I can again use my keyboard to play the same track in the background. so the react-h5 does not unmount.

Thanks in advance

audio play automatically on `src` change with unique URL but same audio when `autoPlay` is `false`

if (src !== prevProps.src) {

In here, if src changes, audio gets played auto even we say autoPlay is false.

We should either add one more condition like ... && autoPlay or completely disable this feature. Otherwise, in some cases, audios get played all the time.

For example; I regularly update components and when components updated, links get refreshed. Audio is same but each time update made, there is an unique encoded URL for each audio. So, with default, even if i select to not play audio automatically, its get played by this library because of this condition.

I've removed this on my repository and point the package there. I can create PR for this, if you want.

Just let me know which path should we follow here:

  • a. adding one more condition
  • b. completely remove this line

V2 Features

Thanks all for supporting this project. I haven't thought about this library can get more than 1000 downloads per week. That makes me feel I have the responsibility to make it better.

Here are V2.0.0 features I'm proposing:

  • Stop using inline style. Use external scss instead. (Pure css will also be provided.)
    • Developers will be able to overwrite scss variables to overwrite styles
  • Add options to enable/disable "Previous" and "Next" button, onClickPrevious and onClickNext will also be supported. However, a playlist component won't be included, developers need to implement their own playlist component, because I want this library to be more focus on the player itself
  • Add option to enable/display "Volume" control, because volume won't be supported on some mobile OSs
  • A11y support

Other features TBD. Feel free to discuss about it.

How does the player handle error responses

A project I'm working on has temporary media URL's to prevent hotlinking to media sources. The media URL is valid for 70 minutes, and after this the media URL returns a 401. I noticed that the audio player keeps retrying to load the data instead of aborting. I added the onError to catch this event, and show a friendly message that the media URLhas expired. but it does not seem to catch the error response. Or do I need to use the onPlayError event instead?

Regards,
Sander

Support long duration display with hours

Duration always shows as minutes:seconds e.g. 109:18 for a long duration > 1 hour
Would be great to display it in human readable form: 1:49:18 in hh:mm:ss format.

Is that something possible with the current props?

Scenario: seminar talks typically all around 1-2 hours

got audio is undefined when componentWillUnmount

hi
I got audio variation is undefined when componentWillUnmount.

it happened in CurrentTime.js, Duration.js, ProgressBar.js, and VolumeBar.js when componentWillUnmount

and I change it to this, everything goes fine.

CurrentTime.js
`
_proto.componentWillUnmount = function componentWillUnmount() {
var audio = this.props.audio;

if( audio && this.hasAddedAudioEventListener ) {
  audio.removeEventListener('timeupdate', this.handleAudioCurrentTimeChange);
  audio.removeEventListener('loadedmetadata', this.handleAudioCurrentTimeChange);
  this.hasAddedAudioEventListener = false;
}

};
`

Duration.js
`
_proto.componentWillUnmount = function componentWillUnmount() {
var audio = this.props.audio;

if (audio && this.hasAddedAudioEventListener) {
  audio.removeEventListener('durationchange', this.handleAudioDurationChange);
  this.hasAddedAudioEventListener = false;
}

};
`

VolumeBar.js
`
_proto.componentWillUnmount = function componentWillUnmount() {
var audio = this.props.audio;

if (audio && this.hasAddedAudioEventListener) {
  audio.removeEventListener('volumechange', this.handleAudioVolumeChange);
  this.hasAddedAudioEventListener = false;
}
clearTimeout(this.volumeAnimationTimer);

};
`

ProgressBar.js
`
_proto.componentWillUnmount = function componentWillUnmount() {
var audio = this.props.audio;

if (audio && this.hasAddedAudioEventListener) {
  audio.removeEventListener('timeupdate', this.handleAudioTimeUpdate);
  audio.removeEventListener('progress', this.handleAudioDownloadProgressUpdate);
  this.hasAddedAudioEventListener = false;
}

clearTimeout(this.downloadProgressAnimationTimer);

};
`

please check it

Thanks a lot : )

Screen Shot 2020-03-03 at 12 10 49 AM

Screen Shot 2020-03-03 at 12 11 05 AM

Screen Shot 2020-03-03 at 12 12 30 AM

Click on progress bar as well as drag.

Hello,

Really like this player - nice and customizable.

Was trying to implement clicking event so that when you click on the progress bar, the indicator moves to that location and the play progress is updated.

Here's what I have but the slider indicator position is incorrect so maybe you can help:

bar.addEventListener('click', e => {
    console.log('bar clicked!')
    const target =
        e.target.nodeName === 'DIV' ? e.target.parentNode : e.target
    const width = target.clientWidth
    const rect = target.getBoundingClientRect()
    const offsetX = e.clientX - rect.left
    const duration = this.audio.duration
    const audio = this.audio
    const currentTime = (audio.duration * offsetX) / width

    this.setState({
        currentTime,
        duration,
        // barWidth,
        dragLeft: offsetX
    })
})

I think my math is wrong somewhere so hopefully you can point the way forward.

Thanks!

Use with soundcloud

Is there any way I can use it with soundCloud, or any other audio streaming?

Is there a way to get just the time/progress bar?

If I pass:

 customIcons={{
  play: null,
  pause: null,
}}

The play/pause icon still shows up. I presume this is by design.

I want to control the player through other buttons on the UI.

Would it be possible to add a hideAllControls param that hides everything except the time/progress bar?

Auto Play Bug? Backspace -> command + s = Auto Play

Hi, lhz516.
I was using this component with true autoplay status.
I was writing a program by starting VSCode with the screen displaying this component in the tab of the browser.

When I pressed ⌘ + s after pressing Backspace to fix and save the program, Auto Play happened.

Is this a bug?

Package version: 3.1.0
React version: 16.12.0
Browser and its version: Google Chrome 81.0.4044.138 (Official Build) (64 bit)
OS and its version: macOS Catalina 10.15.4

Thank You.

cannot override scss variable

Hi, first thank you for this good player.

I am using CRA with node-sass and can't seem to find a way to override the SCSS variable.

I import the variables before react-h5-audio-player style like that :

import 'globals.scss';
import 'react-h5-audio-player/src/styles.scss';

where in my global.scss file I have :

$rhap_theme-color: #000000;

So as I understand it it should override the one defined in react-h5-audio-player/src/styles.scss because it has the default flag.

What's wrong ?

ReferenceError: TouchEvent is not defined

First of all, really great product!!
Using it on our website and it looks so nice and works really well (especially on mobile).
The only error we are getting from Sentry is

ReferenceError: TouchEvent is not defined.

I tried to reproduce and found that on Desktop (Safari and Firefox) the progress bar cannot be controlled. Meaning that clicking or sliding the progress bar has no effect. Chrome works though.
Just wanted to know, if that issue is new to you or if maybe I did something wrong while implementing it. Thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.