react-h5-audio-player icon indicating copy to clipboard operation
react-h5-audio-player copied to clipboard

Using multiple <source> tags as children instead of the "src" property doesn't seem to work

Open mysticflute opened this issue 1 year ago • 1 comments
trafficstars

Describe the bug

<audio> tags support multiple <source> tags as children, instead of using the src property, as demonstrated here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio#usage_notes

The reason for doing this is to provide different file types and let the browser determine the best source.

<audio controls>
  <source src="myAudio.mp3" type="audio/mpeg" />
  <source src="myAudio.ogg" type="audio/ogg" />
</audio>

While the src prop is marked as optional for the React component, it doesn't seem to be able to actually play the audio if it's not specified. It might be because there is code checking that the src property is defined before invoking the play method on the underlying audio tag.

Environment

Package version: 3.9.1 React version: Browser and its version: OS and its version:

mysticflute avatar Oct 08 '24 00:10 mysticflute

possibly caused by this line: https://github.com/lhz516/react-h5-audio-player/blob/acec82a0d60b9bbba8348e9d49cdc2786ba9d79e/src/index.tsx#L207

maybe a fix would be to change this to check that src is truthy or children is not empty?

mysticflute avatar Oct 09 '24 20:10 mysticflute

multi source is not supported. if you need playlist feature, I suggest you to manually maintain the list in a state.

See example: https://github.com/lhz516/react-h5-audio-player/blob/acec82a0d60b9bbba8348e9d49cdc2786ba9d79e/stories/playlist.tsx

lhz516 avatar Dec 18 '24 19:12 lhz516

Thanks for your response! Are there any technical reasons not to support multiple source tags? Like if I were to make a fork, do you think the existing code is incompatible with such a change without a lot of work?

mysticflute avatar Dec 19 '24 04:12 mysticflute

@mysticflute I actually misunderstood. I thought you were asking about a list of different songs.

For multi <source>s, I'm not sure if it works well with the custom UI, you can create a PR if you are interested.

lhz516 avatar Dec 30 '24 07:12 lhz516

@mysticflute I actually misunderstood. I thought you were asking about a list of different songs.

For multi <source>s, I'm not sure if it works well with the custom UI, you can create a PR if you are interested.

Ok, great! I will take a look.

mysticflute avatar Dec 30 '24 16:12 mysticflute

@lhz516 hey, I started taking a look at this. Do you mind reopening it?

mysticflute avatar Jan 09 '25 00:01 mysticflute

also it seems like you might be in the middle of some changes? (jest tests are currently disabled)

mysticflute avatar Jan 09 '25 00:01 mysticflute

@lhz516 I can send a PR when you are ready.

mysticflute avatar Jan 26 '25 21:01 mysticflute

@lhz516 checking again on this.

mysticflute avatar Feb 23 '25 03:02 mysticflute

@lhz516 hey just checking again if you have some time. I'd like to fix this and possibly other issues as well.

mysticflute avatar May 06 '25 20:05 mysticflute

@lhz516 checking again if I can do a PR for this?

mysticflute avatar Sep 01 '25 20:09 mysticflute

@mysticflute sorry for the delay. feel free to create a PR!

lhz516 avatar Sep 02 '25 06:09 lhz516